Write-Eventlog source name missing

Welcome Forums General PowerShell Q&A Write-Eventlog source name missing

Viewing 2 reply threads
  • Author
    • #206679
      Topics: 40
      Replies: 119
      Points: 646
      Rank: Major Contributor

      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.WriteEventLogCommand

      I ran this command

      [system.diagnostics.eventlog]::SourceExists(“System Restart”)



      Any Ideas?


      Thank you


      • This topic was modified 11 months ago by Tom Grassi.
    • #206691
      Topics: 6
      Replies: 20
      Points: 68
      Helping Hand
      Rank: Member

      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."

    • #206694
      Topics: 40
      Replies: 119
      Points: 646
      Rank: Major Contributor

      Hi GNART

      OMG a little space in the wrong place.

      Thanks for the quick response.





Viewing 2 reply threads
  • The topic ‘Write-Eventlog source name missing’ is closed to new replies.