Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3323
  • Last Modified:

Powershell Cmdlets to Write to the Event Log

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
jloomans
Asked:
jloomans
  • 2
1 Solution
 
BSonPoshCommented:
$EventLog.WriteEntry("Error in processing","ERROR")
0
 
jjozCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now