Write-Eventlog source name missing

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

Viewing 2 reply threads
  • Author
    Posts
    • #206679
      Participant
      Topics: 32
      Replies: 105
      Points: 533
      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”)
      True

       

       

      Any Ideas?

       

      Thank you

      Tom

      • This topic was modified 3 months ago by Tom Grassi.
    • #206691
      Participant
      Topics: 6
      Replies: 16
      Points: 47
      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
      New-Eventlog -logname System -source "System Restart"
      Write-EventLog -Logname System -source "System Restart" -EntryType Information -EventId 99 -Message "System Restart for Security updates."

    • #206694
      Participant
      Topics: 32
      Replies: 105
      Points: 533
      Rank: Major Contributor

      Hi GNART

      OMG a little space in the wrong place.

      Thanks for the quick response.

       

      Tom

       

       

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