I've included some handy wrapper functions to make working with events and scriptblocks a bit easier - download the example script called "event handling wrapper functions" from the Releases page.
NOTE: your ScriptBlocks will only be called if you're inside a Do-Events loop.
1# Add-PSSnapin PSEventing 2# $fsw = new-object system.io.filesystemwatcher 3# $fsw.Path = "c:\temp" 4# $fsw.EnableRaisingEvents = $true 5# Add-EventHandler (get-variable fsw) deleted { param([System.Management.Automation.PSVariable]$variable, [EventArgs]$args) ... do stuff ... } 6# Do-Events $false
an example how to wire up an event using the wrapper scripts
Page rendered at Friday, September 05, 2008 9:50:58 PM (Eastern Standard Time, UTC-05:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.