write-eventlog -logname system -source MyScript -eventID 1 -message "test" -entrytype Information
Write-EventLog : The source name "MyScript" does not exist on computer "localhost".
At line:1 char:15
+ write-eventlog <<<< -logname system -source MyScript -eventID 1 -message "test" -entrytype Information
+ CategoryInfo : InvalidOperation: (:) [Write-EventLog], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteEventLogCommand
To get around this, you can easily register your own name
[System.Diagnostics.EventLog]::CreateEventSource("MyScript", "System")
Then try the write-eventlog command again, and it will work fine.
No comments:
Post a Comment