Any examples for watching proccess create/exit?

Dec 19, 2007 at 1:35 PM
Edited Dec 19, 2007 at 1:37 PM

I'm struggling with PSEventing to make my script look for process to exit after launching it on remote host. Code is below

$query = New-Object System.Management.WqlEventQuery
$query.EventClassName = "__InstanceDeletionEvent"
$query.WithinInterval = New-TimeSpan -seconds 50
$query.Condition = "TargetInstance ISA 'Win32_Process'"
$watcher = New-Object System.Management.ManagementEventWatcher ($query)
Connect-EventListener watcher EventArrived -Verbose
$e = Get-Event
if ($e.TargetInstance.ProcessID -eq 2344){break}
while ($true)

How do I stop my code if I know ProcessID of remote process which is supposed to be exiting?
Code above is
Dec 27, 2007 at 11:44 PM
Hi ArtisticCheese,

Just a quick note to let you know I've noticed this post! ;-) I'll post a working example later this evening or tomorrow - sorry for not noticing you sooner.

- Oisin