Você também pode usar o WMI e iniciar remotamente um processo. Não será interativo e você terá que confiar que isso terminará por conta própria. Isso não requer nada no computador remoto além de portas abertas para o WMI.
Function New-RemoteProcess {
Param([string]$computername=$env:computername,
[string]$cmd=$(Throw "You must enter the full path to the command which will create the process.")
)
$ErrorActionPreference="SilentlyContinue"
Trap {
Write-Warning "There was an error connecting to the remote computer or creating the process"
Continue
}
Write-Host "Connecting to $computername" -ForegroundColor CYAN
Write-Host "Process to create is $cmd" -ForegroundColor CYAN
[wmiclass]$wmi="\$computername\root\cimv2:win32_process"
#bail out if the object didn't get created
if (!$wmi) {return}
$remote=$wmi.Create($cmd)
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
}
}
Uso da amostra:
New-RemoteProcess -comp "puck" -cmd "c:\windows\notepad.exe"