Problem
You want to create or remove an event log.
Solution
To create an event log, use the [System.Diagnostics.EventLog]:: CreateEventSource() method from the .NET Framework:
$newLog =
NewObject Diagnostics.EventSourceCreationData
"PowerShellCookbook","ScriptEvents"
[Diagnostics.EventLog]::CreateEventSource($newLog)
To delete an event log, use the [System.Diagnostics.EventLog]::Delete() method from the .NET Framework:
[Diagnostics.EventLog]::Delete("ScriptEvents")
Discussion
The [System.Diagnostics.EventLog]::CreateEventSource() method from the .NET Framework registers a new event source (PowerShellCookbook in the solution) to write entries to an event log (ScriptEvents in the solution). If the event log does not exist, the CreateEventSource() method creates the event log.
The [System.Diagnostics.EventLog]::Delete() method from the .NET Framework deletes the event log altogether, along with any event sources associated with it. To delete only a specific event source, use the [System.Diagnostics.EventLog]:: DeleteEventSource() method from the .NET Framework.
Be careful when deleting event logs, as it is difficult to recreate all the event sources if you delete the wrong log by accident.