I’m into a situation that I want to write the activity that was carried out into the Event Viewer (say the Application).
I’ve a PowerShell script but has incorporated the following in the beginning and the end of the script.
First I need to register the event into the server’s event viewer. I call it as “InFront Maintenance”
In the PowerShell, I only execute once to record it down.
New-EventLog –LogName Application –Source “InFront Maintenance”
Once it’s registered, then I incorporated the following into my beginning of my script the activity that I need to carry out.
Note : If you do not register, the next line you execute to write to event viewer, you’ll definitely hit the error. This is because the “SOURCE” is not registered.
Write-EventLog –LogName Application –Source “InFront Maintenance” –EntryType Information –EventID 1 –Message “Maintenance Spoke A.”
So in the event viewer you’ll be able to see something like this
At the end of my script I indicate as follow :
Write-EventLog –LogName Application –Source “InFront Maintenance” –EntryType Information –EventID 1 –Message “End Maintenance Spoke A”
In the event viewer you’ll see like this :
So to summary it :
To register for the first time the event (just once)
- New-EventLog –LogName Application –Source “InFront Maintenance”
Insert beginning on my PowerShell Script
- Write-EventLog –LogName Application –Source “InFront Maintenance” –EntryType Information –EventID 1 –Message “Maintenance Spoke A.”
Insert at the end of my PowerShell Script
- Write-EventLog –LogName Application –Source “InFront Maintenance” –EntryType Information –EventID 1 –Message “End Maintenance Spoke A”
Just change the Pink for your event, and the Yellow for the General Descriptions.
Thanks to the Scripting Guy Site , Ed Wilson!!
keynote : How to write to Event Viewer with powershell, using powershell to write event,event log, application log event viewer, eventviewer with PowerShell, record activity into event viewer
No comments:
Post a Comment