I have a catch clock that works like this:
catch  [System.InvalidOperationException]
{
     Process-Exception($_.Exception,1111) 
}
And then I want to process the exception like this:
# Write exceptions to eventlog and reset socket
function Process-Exception { param ($exception, $eventID)
    $dateTime = Get-Date
    #Write-EventLog -ComputerName $env:COMPUTERNAME -Source PowerShell -LogName Application -EventId $eventID `
    #for now: write-host [string] instead of -Message [string]
    write-host "Date and time:`t" + $dateTime + "`r`n`" 
    write-host "Exception Source:`t" + $exception.Source   
    write-host "Error Code:`t"+ $exception.NativeErrorCode  
    write-host "Exception Message:" + $exception.Message  
    write-host "Stack Trace:`t" + $exception.StackTrace + "`r`n`r`n`
    $socket = $null
}
Where `t is a tab and the $exception properties needs to be accessed. Unfortunately when I do this the exception is not send to the method, only the error code (this case 1111) is send. THe message is:
 write-host   Stack Trace:   + Cannot find type [[System.InvalidOperationException]]: 
make sure the assembly containing this type is loaded. 9999.StackTrace + 
How can I send the full exception to the method? And if you have improvements to the code let me know!
 
     
     
     
    