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 #65 New-EventLog

    Posted on February 22nd, 2010 Jonathan Medd 2 comments

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

    What can I do with it?

    Create a custom Event Log.

    Example:

    Create a custom Event Log named App1 with an event source of AppEvent. Use the Get-EventLog cmdlet to confirm it has been created. Tip: New-EventLog requires a PowerShell session with elevated privileges.

    New-EventLog -LogName App1 -Source AppEvent
    Get-EventLog -List

    You can see that the App1 Event Log has been created.

    New-EventLog1

    You can create entries in this log using the Write-EventLog cmdlet, e.g.

    Write-EventLog -LogName App1 -Source AppEvent -ID 1020
    -Message "Error 1020 has occured"

    Here’s confirmation in Event Viewer that the App1 Event Log exists and we have created the above entry in it.

    New-EventLog2

    How could I have done this in PowerShell 1.0?

    You could have used the .NET System.Diagnostics.EventLog class and the CreateEventSource method to create a custom event log.

    $LogDetails = 
    New-Object System.Diagnostics.EventSourceCreationData "AppEvent", "App1"
    [System.Diagnostics.EventLog]::CreateEventSource($LogDetails)

    1000 things 1% better!

     

    2 responses to “PowerShell 2.0: One Cmdlet at a Time #65 New-EventLog” RSS icon


    Leave a reply