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 {