less than 1 minute read

How to launch/start a process on a remote machine when this one does not have Powershell ? … WMI!

Solution 1 (Ravikanth Chaganti, see his WMI book! Must read!)

$proc = Invoke-WmiMethod `
        -ComputerName Test `
        -Class Win32_Process `
        -Name Create `
        -ArgumentList "Notepad.exe"
Register-WmiEvent `
    -ComputerName test `
    -Query "Select * from Win32_ProcessStopTrace Where ProcessID=$($proc.ProcessId)" `
    -Action { Write-Host "Process ExitCode: $($event.SourceEventArgs.NewEvent.ExitStatus)" }

Solution 2 (The Lonely Administrator)

Function New-RemoteProcess {
        [string]$cmd=$(Throw "You must enter the full path to the command which will create the process.")


    Trap {
        Write-Warning "There was an error connecting to the remote computer or creating the process"

    Write-Host "Connecting to $computername" -ForegroundColor CYAN
    Write-Host "Process to create is $cmd" -ForegroundColor CYAN


    #bail out if the object didn't get created
    if (!$wmi) {return}


    if ($remote.returnvalue -eq 0) {
        Write-Host "Successfully launched $cmd on $computername with a process id of" $remote.processid -ForegroundColor GREEN
    else {
        Write-Host "Failed to launch $cmd on $computername. ReturnValue is" $remote.ReturnValue -ForegroundColor RED

Leave a comment