Solved

Powershell Cmdlets to Write to the Event Log

Posted on 2008-10-29
3
3,271 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
Dropbox 3 72
Free runner service software 2 77
Check version 13 71
Please explain "Multi-Tenant Services" 5 65
A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video demonstrates basic masking and how to edit the mask to reveal the desired image.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

867 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

21 Experts available now in Live!

Get 1:1 Help Now