Top 10 winexe Example to run powershell script from Linux

Top 10 winexe examples  to run PowerShell or Batch script from Linux

This Article is about the Winexe Examples, Winexe remotely executes commands on Windows NT/2000/XP/2008/2012 systems from Linux systems.

Download Winexe hare.
In Daily Automation task we need to communicate so many time from Linux to Windows vice versa. WinExe is a easy to use tool which solved this challenge with some simple commands In this article i cover some of the examples for WinExe.

winexe – Remote Windows-command executor
[root@onclick ~]# winexe --help
winexe version 1.1
This program may be freely redistributed under the terms of the GNU GPLv3
Usage: winexe [OPTION]... //HOST COMMAND
  -?, --help                                  Display help message
  -U, --user=[DOMAIN/]USERNAME[%PASSWORD]     Set the network username
  -A, --authentication-file=FILE              Get the credentials from a file
  -k, --kerberos=STRING                       Use Kerberos, -k [yes|no]
  -d, --debuglevel=DEBUGLEVEL                 Set debug level
      --uninstall                             Uninstall winexe service after remote execution
      --reinstall                             Reinstall winexe service before remote execution
      --system                                Use SYSTEM account
      --profile                               Load user profile
      --convert                               Try to convert characters between local and remote code-pages
      --runas=[DOMAIN\]USERNAME%PASSWORD      Run as user (BEWARE: password is sent in cleartext over net)
      --runas-file=FILE                       Run as user options defined in a file
      --interactive=0|1                       Desktop interaction: 0 - disallow, 1 - allow. If you allow use
                                              also --system switch (Win requirement). Vista do not support
                                              this option.
      --ostype=0|1|2                          OS type: 0 - 32-bit, 1 - 64-bit, 2 - winexe will decide.
                                              Determines which version (32-bit or 64-bit) of service will be
[root@onclick ~]#

winexe Usage Example

1. List Program Files folders and files.

 winexe -U HostName/Administrator%Password123 //IP Address 'dir "/Program Files"'

2. Copy file from one folder to another folder.

 winexe -U HostName/Administrator%Password123 //IP Address 'copy C:/myfile.txt C:/user/desktop/'

3. Restart server from Winexe

 winexe -U HostName/Administrator%Password123 //IP Address 'shutdown /r'

4. Check the Services status

 winexe -U HostName/Administrator%Password123 //IP Address 'sc query "ServiceName" | find "RUNNING"'

5.Run ipconfig windows command from Linux

 winexe -U HostName/Administrator%Password123 //IP Address "ipconfig /all"

6. With the given credentials (-U ‘Administrator%password123’), connect to the remote server (//IP Address), and execute the given command (‘cmd.exe /c echo “Hello World”‘):

winexe -U 'Administrator%Password123' //IP Address 'cmd.exe /c echo "Hello World"'

7. Run PowerShell commands from Linux:

  winexe -U 'Administrator%Password123' //IP Address 'powershell.exe Get-Process'

8. Run Windows Batch Script with Name argument: Create a bat file in and copy paste this code

@echo hello %1

and save to task.bat. Now call this script from Linux with below command.

 winexe -U 'Administrator%Password123' //IP Address 'cmd.exe /c "C:/folder/task.bat Name"'</pre>
Output : hello Name

Batch files can only handle parameters %0 to %9

%0 is the program name as it was called,
%1 is the first command line parameter,
%2 is the second command line parameter,
and so on till.%9

9. Run Power Shell Script from Linux using Winexe.

winexe -U" // "cmd.exe /c powershell.exe C:/folder/task.ps1"

10. Run Power Shell Script with Name argument from Linux using Winexe.

 winexe -U" // 'cmd.exe /c "powershell.exe C:/folder/task.ps1 Name"'
Hope you enjoy this article.

You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *