Problems with catch in PowerShell

Question:

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

Answer:

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

Source:

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

Leave a Reply