PowerShell: Can't catch UnauthorizedAccessException thrown by get-content PowerShell: Can't catch UnauthorizedAccessException thrown by get-content powershell powershell

PowerShell: Can't catch UnauthorizedAccessException thrown by get-content


try/catch will catch only terminating errors.You can use the following command on top of your script to make all errors a terminating error

$erroractionPreference="stop"

@Shay Levy has the explaination here : https://stackoverflow.com/a/8381798/381149