Windows Remote Execution

This article compares different ways to run commands or executable remotely on one or multiple windows computers. I have came up with 4 option:

- WMI script
- WMIC
- Power Shell
- PSExac
- Task Scheduler
Those options are build in in Operating System with exception of PSexec that is part of system internal tools (now part of Microsoft) also available to download for free. There are many 3-rd party products that can execute command remotely like Microsoft System Center Configuration Manager, Microsoft System Center Operation manager,  IBM Tivoli, 1E, BNC, HP OpenView, Novell ZenWork, but all of them requires that you have an agent installed on remote computer.

Differences between  methods

I made a small comparison chart that summarizes the differences between these methods:

 FeaturesWMI script
 WMICPsexec
Power Shell
Task Scheduler
Available in all Windows version by Default from XP and later
 yes yesno - but it can be download for free
 yes - but the remote computer must be configured for remote management
 yes
Protocol / Service used
RPC, WMI
RPC, WMIRPC, Admin$ and IPC$ shares 
WS-Management protocol,RPC and WMI
Task Scheduler service and RPC
 Pass credential in clear test
 yes yes yesyes
yes
Requires WMI connectivity
yes
 yesno
no
no
Can use the system account for remote execution
no
 no yes noyes         
 Redirect command's output's back to user console no yes yes yes no
 Instant run
 yes yes yes yes no - 1 minute wait
 Requires RPC connectivity
 yes yes yes yes yes
 Enabled by default
yes
yes
no - need to download
no - need to enable remote execution
yes

Syntax Examples:


WMIC"

WMIC /node:ComputerName process create call "cmd.exe /c ipconfig /all >c:\ipconfig.txt"
or
wmic /NODE: "RemoteComputer bios get serialnumber

PSexec:
psexec \\computername ipconfig /all


PowerShell:

Run the PSscript.ps1 script on the Server1 computer. The script is located on the local computer. The script runs on the remote computer and the results are returned to the local computer:

PS C:\> invoke-command -filepath c:\scripts\PSScript.ps1 -computerName Server1

Task Scheduler:
SCHTASKS /create /tn "My test Script" /tr "\"c:\script.cmd\" arguments" /sc daily /sd 3/29/2015 /st 11:00

 
WMI Script:

    '  Initiate WMI connection to remote computer
    '--------------------------------------------------------------------------
    Set objWMIService = GetObject("winmgmts:& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process")
   ' Run script
   '-----------------------------------------------------------------------------
    Return = objWMIService.Create(strCmd,null,null,intProcessID)
    if Return = 0 Then
        Wscript.Echo strCmd & " Started with a process ID of & intProcessID & "."
    Else
        Wscript.Echo strCmd & " Could not be started. Error: " & Return & "."
    End If



Comments