Problems with catch in PowerShell


I have a problem with the catch command. I have the following script I’m trying to process:

Every time I run this though I am not getting anything in the catch block. Here is the error reported that I get from the script:

Any ideas?

A working solution (thanks to PK and Patrick for their combined contributions):


Try catching System.Management.Automation.RuntimeException instead of System.InvalidOperationException.


Problems with catch in PowerShell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply