Solved

Powershell Cmdlets to Write to the Event Log

Posted on 2008-10-29
3
3,290 Views
Last Modified: 2013-11-25
I'm modifying a Powershell script to write the Application Event Log in order to log errors.  I using the code attached.  What is the code to specify that the event is a warning or an error?
$EventLog = new-object System.Diagnostics.EventLog('Application')
$EventLog.MachineName = "."
$EventLog.Source = "Script"
$EventLog.WriteEntry("Error in processing")

Open in new window

0
Comment
Question by:jloomans
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
BSonPosh earned 125 total points
ID: 22831574
$EventLog.WriteEntry("Error in processing","ERROR")
0
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22831580
0
 
LVL 1

Expert Comment

by:jjoz
ID: 27662513
Still in Error guys:

Exception calling "WriteEntry" with "2" argument(s): "The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security."
At :line:4 char:20
+ $EventLog.WriteEntry <<<< ("Testing Error in processing","ERROR")

$EventLog = new-object System.Diagnostics.EventLog("System")
$EventLog.MachineName = "."
$EventLog.Source = "Script"
$EventLog.WriteEntry("Testing Error in processing","ERROR")

Open in new window

0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If your app took Google’s lash recently, here are the 5 most likely reasons.
Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
The viewer will learn common shortcuts with easy ways to remember them. The viewer will then learn where to find all of the keyboard shortcuts, how to create/change them, and how to speed up their workflow.
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question