Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PS Errors. Handling output of command write-EventLog

Status
Not open for further replies.

woter324

Technical User
Jan 26, 2007
179
GB
Hi,

I have a command that errors. I know why it errors but want to write it to the windows event log. I can write my own text to the event log, but I want it to write the stderr to the event log.

The short version of my code:
Code:
try{
 $crd = credentials $server $user
 $session = New-PSSession -ComputerName $server -Authentication 'Credssp' -Credential $crd 
}
catch{
 Write-EventLog -EntryType Warning -EventId 7551 -LogName Application -Message "Error   trying to connect to $server. $session " -Source MyApp
			
}

It is $session that errors. When I run the command I get a whole list of instructions on how to correct the problem, but this is not written to the event log.

How does one get the output of the command into the write-Eventlog.

Any pointer would be greatly apreciated.

Thanks

W.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top