ReneDK
asked on
PowerShell and catch exception
Hi,
this pretty simple piece of code is causing me a problem.
Why doesn't it catch the UnauthorizedAccessExceptio n
try{ Get-ChildItem <path to folder with no access>}
catch{ "exception" }
I get the following error output:
Get-ChildItem : Access to the path '<path to folder with no access>' is denied
.
At line:1 char:19
+ try{ Get-ChildItem <<<< <path to folder with no access>}catch{ "exception"
}
+ CategoryInfo : PermissionDenied: (<path to folder with no access>:String) [Get-ChildItem], UnauthorizedAccessExceptio n
+ FullyQualifiedErrorId : DirUnauthorizedAccessError ,Microsoft .PowerShel l.
Commands.GetChildItemComma nd
this pretty simple piece of code is causing me a problem.
Why doesn't it catch the UnauthorizedAccessExceptio
try{ Get-ChildItem <path to folder with no access>}
catch{ "exception" }
I get the following error output:
Get-ChildItem : Access to the path '<path to folder with no access>' is denied
.
At line:1 char:19
+ try{ Get-ChildItem <<<< <path to folder with no access>}catch{ "exception"
}
+ CategoryInfo : PermissionDenied: (<path to folder with no access>:String) [Get-ChildItem], UnauthorizedAccessExceptio
+ FullyQualifiedErrorId : DirUnauthorizedAccessError
Commands.GetChildItemComma
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Aaah... As I tried to hide the error output temporarily I added ErrorAction AND and the same time remove the try/catch. Didn't realize they had to be combined. Thanks a lot.
ASKER