PowerShell Log
I'm starting to have many jobs that run powershell scripts on some servers so I decided to update the scripts in order to write to the event logs on the servers.
I decided to create my own log in order to be free to do anything I want with it and I called it "Powershell Jobs". I also added a source for every job. All that with the New-EventLog command.
I then added error handling code to the scripts using the $error.Count value in order to check if the last command had any errors and the $error[0] for the error message.
I then write to the above log using the Write-EventLog command.
That way I know what happened for every job and I can get it on Splunk (or any other syslog server) too.
One more thing, depending on the result of a command I write error or information events and I'm using a seperate ID for every event type.
I decided to create my own log in order to be free to do anything I want with it and I called it "Powershell Jobs". I also added a source for every job. All that with the New-EventLog command.
I then added error handling code to the scripts using the $error.Count value in order to check if the last command had any errors and the $error[0] for the error message.
I then write to the above log using the Write-EventLog command.
That way I know what happened for every job and I can get it on Splunk (or any other syslog server) too.
One more thing, depending on the result of a command I write error or information events and I'm using a seperate ID for every event type.