Write to event log batch file
Active Oldest Votes. EDIT In your case, try this. Improve this answer. Thats great but it reports every time to the event viewer even on success?
Otherwise the formatting of the message will fail. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Page Discussion Edit History. I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack. Write to Windows event log From Rosetta Code.
Jump to: navigation , search. Library: Shell xtra. Library: WinEventLog. If you work in an enterprise, you most likely have some type of central monitoring system that collects errors from your event logs. Why not use that same system to capture and report when one of your Windows PowerShell scripts goes wrong? It looks like the one we probably need is Write-EventLog. To try this out, I am going to write a test message to the Application event log. This should be fairly straightforward:.
After running this command, I would expect a new message to show up in the Application event log. Run this on your computer and then check the event logs. You got an error message? Note If you received a slightly different error that states not all event logs Security could be scanned, you need to run Windows PowerShell as an Administrator.
I will explain a little more about this later. So, how in the world can we use the event log if we have to have a Source parameter but the source we want to use is not on the server? If you look back at the first screenshot, you will see another cmdlet in the list that will help us out: New-EventLog. The New-EventLog cmdlet can be used not only to create a brand new event log on the computer, but it can also create a new source that can be used when you write to the event log.
I have actually used this in some instances for custom code in a SharePoint farm. The custom code being deployed needed to write information to the event logs, but the application pool account did not have the administrative rights to create the source.
As you can see, the Write-EventLog now returns with no error.
0コメント