PowerShell 2.0: One Cmdlet at a Time 94 Get-EventSubscriber

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Get-EventSubscriber cmdlet.

What can I do with it?

Retrieve event subscribers from the current session.

Example:

Use the Register-ObjectEvent cmdlet to register for an event to check for new processes, use the ManagementEventWatcher .NET object to form the basis of the object to monitor and save information including the date and time out to a log file.

Execution of Get-EventSubscriber will then show details of the event subscribed to.

$query = New-Object System.Management.WqlEventQuery “__InstanceCreationEvent”, (New-Object TimeSpan 0,0,1), “TargetInstance isa ‘Win32_Process’” $processWatcher = New-Object System.Management.ManagementEventWatcher $query Register-ObjectEvent -inputObject $processWatcher -eventName “EventArrived” -Action {“A new process started at " + (Get-Date) | Out-File c:\log.txt -Append} Get-EventSubscriber

You will see below the details which are returned by default

How could I have done this in PowerShell 1.0?

Register-ObjectEvent and Register-WMIEvent contain examples of how to create events in .NET

1000 things 1% better