Forum Discussion
PeteMitch99
Apr 14, 2021Copper Contributor
Different $error results in a ISE 5.1 remote session and a local session
Hi, I am getting different results rewriting an error object in a local and remote pssession and I am wondering if anyone can explain why? Here is the simple code: Function PSitemChangeError ...
farismalaeb
Apr 21, 2021Iron Contributor
HI
It seems that Throw behavior change when being on a remote or locally.
I did this small change and based on what I see, it's working. can you try and let me know?
Function PSitemChangeError ($Errorobj,$CustomErrorMessage)
{
$newline = "`r`n"
$OrginalExceptionMessage = $Errorobj.exception.message
$Errorobj.errordetails = "[Custom Message] $CustomErrorMessage $newline`[Orginal Message] $OrginalExceptionMessage"
write-verbose $Errorobj -verbose
return $Errorobj
}
Try
{1/0}
catch
{
$MyError=(PSitemChangeError -Errorobj $psitem -CustomErrorMessage "Some Custom Error")
$MyError
Throw $MyError.ErrorDetails
}