我有一段代码如下:
...
32: try {
33: set-acl -aclObject $AC -path $o.fullname
34: } catch [System.UnauthorizedAccessException] {
...
在执行期间,我得到了这个:
set-acl : Attempted to perform an unauthorized operation. At C:\script.ps1:33 char:3 + set-acl -aclObject $AC -path $o.fullname + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (N:\some_path:String) [Set-Acl], UnauthorizedAccessException + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetAclCommand
作为系统运行。 知道为什么没有被捕获吗?
答案 0 :(得分:3)
尝试将ErrorAction
参数设置为Stop
:
set-acl -aclObject $AC -path $o.fullname -ErrorAction Stop