Solved

Powershell Cmdlets to Write to the Event Log

Posted on 2008-10-29
3
3,296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Software for Local History Museum Library 5 90
Recommendation for open source Monitoring 7 101
hp laptop chargers 4 68
Map all network 11 93
If your app took Google’s lash recently, here are the 5 most likely reasons.
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.
Viewers will learn how to use the Hootsuite Dashboard.

739 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