I have a situation where I am connecting to a server and performing an operation using powershell, in that if the error comes then it should goto catch block where I am doing some other operation.
try{
$Result = Invoke-Command -ComputerName "cmpname" -scriptblock {DTExec.exe /File "Z:\aaaaaaaSSIS\zzzzProjects\Z_Test\Integration test\test.dtsx"} -ErrorAction Stop -credential $creds
}
catch {
"****An error occurred reading $file
}
Now in the above case if error is coming in -scriptblock it is not going in catch block. Where as if there is issue in Invoke-Command -ComputerName
then it is going in catch block.
So I need the script to go in catch block when error occurs any where while executing the line and specially of -script block.