Solved

Powershell Cmdlets to Write to the Event Log

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
I previously wrote an article addressing the use of UBCD4WIN and SARDU. All are great, but I have always been an advocate of SARDU. Recently it was suggested that I go back and take a look at Easy2Boot in comparison.
This video will demonstrate how to find the puppet warp tool from the edit menu and where to put the points to edit.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now