Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to write script errors into a custom event log ...

$
0
0

So I've run the following code on one of my servers to create a custom event log and source:

New-EventLog -LogName psLogs -source scripts
Limit-EventLog -overflowaction overwriteasneeded -maximumsize 1MB -logname psLogs
Write-EventLog -LogName psLogs -Source scripts -Message "PsLogs Event Log Setup Complete!" -EventId 0 -EntryType information
Write-Host "PsLogs Event Log Setup Complete!"

This works fine since I ran it as "Administrator"

Next question is how do I incorporate this Event Log into a script that I am running via task scheduler so that if the scheduled script errors it will output the errors to this log?  I would also like to know how to write the Information and Warning types too.

In other words if I run a script that automatically installs printers via a CSV and the thing errors out for any reason I want an entry in my Custom Event Log to appear.



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>