PowerShell Version 1.0 - Event Logging

We have a client with PowerShell 1.0. I know in PowerShell 2.0, I have a batch file Write-EventLog. However, this does not appear in PowerShell 1.0. I want my script to log events in the event log, mainly for debugging purposes.

How can I do this with PowerShell 1.0 :? And I can not upgrade this computer to PowerShell 2.0. This is a machine for the production of customers, and they do not want to touch the software on it.

+3
source share
2 answers

You can use the .NET EventLog class for this. It is quite simple to use, for example:

$eventSource = "MyAppName"
if (![Diagnostics.EventLog]::SourceExists($eventSource))
{
    [Diagnostics.EventLog]::CreateEventSource($eventSource, "Application")
}

[Diagnostics.EventLog]::WriteEntry($eventSource, "message", [Diagnostics.EventLogEntryType]::Error)
+3
source
+1

All Articles