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:
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.
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.