≡ Menu

Powershell: Write-EventLog Error “Write-EventLog : The source name XXX does not exist on computer

If you are using Write-EventLog to write any new events to event log, it is possible that you might see below error.

Write-EventLog : The source name “XXX” does not exist on computer “localhost”.

I am into similar situation today. What I was doing is trying to write a new event in to Application event log with a Event Source that is not already exists in the computer where I am trying. So the error message makes sense. It is saying the source I am trying to use, XXX doesn’t exists. So, how should get this added to list of available event sources in the computer so that it won’t through the error message again.

After little bit of googling, I found the below method promising.

New-EventLog -LogName Application -Source “XXX”

This command creates a new event source in Application Event log with the name XXX. All I need to do is just use this command once and try the write-EventLog cmdlet with the same source name(XXX). It worked this time.

Hope this little trick helps you…

[Update]

There are some dotnet ways available as well to see if a given source is available in EventLog and create one if needed.

To check if the source exists:

PS C:\> [system.diagnostics.eventlog]::SourceExists(“XXX”)
False
PS C:\>

To create a new source entry in event log:

[system.diagnostics.EventLog]::CreateEventSource(“XXX”, “Application”)

 

{ 3 comments… add one }
  • Greg November 11, 2013, 1:21 pm

    Good Stuff…had the exact same question and didn’t have a clue how to solve it. Thanks.

  • lakshmi June 20, 2014, 12:52 pm

    PS C:\Users\Administrator.C1ML06621> Write-EventLog -Source Microsoft-Windows-TaskScheduler -EventId 101 -Message testi
    ng -LogName TaskScheduler
    Write-EventLog : The Log name “TaskScheduler” does not exist in the computer “localhost”.
    At line:1 char:1
    + Write-EventLog -Source Microsoft-Windows-TaskScheduler -EventId 101 -Message te …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [Write-EventLog], InvalidOperationException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteEventLogCommand

    can you help out on this

Cancel reply

Leave a Comment