Scripting. Powershell, VMware, Windows, Active Directory & Exchange. All that kind of stuff…..
RSS icon Email icon Home icon
  • PowerShell 2.0: One Cmdlet at a Time #95 Register-EngineEvent

    Posted on April 30th, 2010 Jonathan Medd No comments

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

    What can I do with it?

    Subscribe to events generated by the PowerShell engine or the New-Event cmdlet.

    Example:

    Subscribe to an event when the PowerShell session exits, and save information including the date and time out to a log file.

    Register-EngineEvent PowerShell.Exiting 
    -Action {"PowerShell exited at " + (Get-Date) | Out-File c:\log.txt -Append}

    Register-EngineEvent

    After closing the PowerShell session (by typing Exit) the date and time it was closed is written to the log file.

    Register-EngineEvent2How could I have done this in PowerShell 1.0?

    PowerShell engine events are a new feature in PowerShell 2.0.

    1000 things 1% better

    Leave a reply