Solved

Powershell Cmdlets to Write to the Event Log

Posted on 2008-10-29
3
3,277 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Image Deployment Tool 9 85
Using MS Code on my Mac 6 68
Determining Project Cost 1 76
PDFMate free PDF Merger. Security concern 8 115
A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
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…
Viewers will learn how to use the Hootsuite Dashboard.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

772 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