Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Adding -Verbose to a Cmdlet Prevents Script From Terminating on Error

$
0
0

Why is it that if you add -Verbose to a cmdlet that if it has a terminating error it does not stop executing the script while otherwise it would have?

For example, the following will fail with a PathNotFound error and the Start-Sleep 10 will never execute:

GCI -Path D:\BadPath\DoesNotExist.txt
Start-Sleep 10

However, if I add -Verbose to the Get-ChildItem I get the same error but the Start-Sleep 10 does execute:

GCI -Path D:\BadPath\DoesNotExist.txt -Verbose
Start-Sleep 10
Is this expected behavior and if so is there a way to make the script terminate in the second scenario? I have also seen this behavior with Remove-Item.

Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>