Reacting to events
Events in .NET occur when something of interest happens to an object. For instance, System.IO.FileSystemWatcher can be used to monitor a file system for changes; when something changes, an event will be raised.
Many different types of objects raise events when changes occur. Get-Member can be used to explore an instance of an object for Event members. For example, a Process object returned by the Get-Process command includes several events, shown as follows:
PS> Get-Process | Get-Member -MemberType Event TypeName: System.Diagnostics.Process Name MemberType Definition ---- ---------- ---------- Disposed Event System.EventHandler Disposed(Syst... ErrorDataReceived Event System.Diagnostics.DataReceivedEv... Exited Event System.EventHandler Exited(System... OutputDataReceived Event System.Diagnostics.DataReceivedEv... PowerShell can react to these events, executing code when an...