Welcome › Forums › General PowerShell Q&A › Write-Eventlog source name missing
- This topic has 2 replies, 2 voices, and was last updated 11 months ago by
Participant.
-
AuthorPosts
-
-
February 27, 2020 at 9:18 pm #206679
Wrote a small script to write to my System Event Log and restart my servers
$Server = hostname
New-Eventlog -logname System -source “System Restart”
Write-EventLog -Logname System -source ” System Restart” -EntryType Information -EventId 99 -Message “System Restart for Security updates.”Write-EventLog : The source name ” System Restart” does not exist on computer “localhost”.
At line:1 char:1
+ Write-EventLog -Logname System -source ” System Restart” -EntryType I …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Write-EventLog], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteEventLogCommandI ran this command
[system.diagnostics.eventlog]::SourceExists(“System Restart”)
TrueAny Ideas?
Thank you
Tom
-
This topic was modified 11 months ago by
Tom Grassi.
-
This topic was modified 11 months ago by
-
February 27, 2020 at 9:47 pm #206691
Hi Tom,
I saw a couple of errors, after fixing I tested and it worked.
1st. The codes as posted used smart quotes (as in MS-Word quotes). Change them to straight double-quotes or single-quote.
2nd. You have a leading space ” System Restart” in the Write-EventLog$Server = hostname<br />New-Eventlog -logname System -source "System Restart"<br />Write-EventLog -Logname System -source "System Restart" -EntryType Information -EventId 99 -Message "System Restart for Security updates."
-
February 27, 2020 at 9:55 pm #206694
Hi GNART
OMG a little space in the wrong place.
Thanks for the quick response.
Tom
-
-
AuthorPosts
- The topic ‘Write-Eventlog source name missing’ is closed to new replies.