Question: try catch is not working in powershell?
Answer: By default, a non-terminating error will not trigger your catch handling. So, if you want to force powershell to catch the error no matter what type it is, you can append -ErrorAction Stop to your InvokeCommand line. ... To set it for the session, type $ErrorActionPreference = Stop at the PowerShell console.