【发布时间】:2015-11-25 16:29:39
【问题描述】:
我在新 NAS (synology) 上恢复了权限受损的文件夹结构。所有文件夹 (+1000) 都包含相同的结构,包含 13 个子文件夹,每个子文件夹都有其特定的权限。
我在同一个驱动器上有一个“示例”结构,现在我正在尝试获取/设置不同文件夹上的 acl。但每次我尝试“Set-Acl”时都会收到这种错误:
Set-Acl : Method failed with unexpected error code 1.
At line:1 char:1
+ Set-Acl -Path ".\1019 Stekene Molenbergstraat" -AclObject $MainAcl
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (N:\WERVEN\WERVE...Molenbergstraat:String) [Set-Acl], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.SetAclCommand
我尝试了很多不同的东西.. 直接在 UNC 上,映射为驱动器,使用 Get-Acl、Set-Acl、GetAccessControl('Access')、SetAccessControl($acl)、绝对路径、相对路径的组合......
$TemplateAcl = Get-Acl ".\{TEMPLATE}"
Set-Acl -Path ".\OTHER" -AclObject $TemplateAcl
# Error..
$TemplateItem = Get-Item ".\{TEMPLATE}";
$TemplateAcl = $TemplateItem.GetAccessControl('Access');
Set-Acl -Path ".\OTHER" -AclObject $TemplateAcl
# Error...
$OtherItem = Get-Item ".\OTHER";
$OtherItem.SetAccessControl($TemplateAcl);
# No error.. but nothing has changed
我可以完全访问此驱动器。我可以在 Windows 中设置权限就好了。使用 robocopy,我可以复制维护其权限的结构。在 PowerShell 中...我不断收到此错误代码 1。
我完全没有想法......
编辑 11 月 22 日 - 第 1 部分
根据 cmets 的要求:
PS N:\WERVEN> $error[0].exception|select *;
Message : Method failed with unexpected error code 1.
Data : {}
InnerException :
TargetSite : Void Persist(System.String, System.Runtime.InteropServices.SafeHandle, System.Security.AccessControl.AccessControlSections, System.Object)
StackTrace : at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, SafeHandle handle, AccessControlSections includeSections, Object
exceptionContext)
at System.Security.AccessControl.FileSystemSecurity.Persist(String fullPath)
at Microsoft.PowerShell.Commands.FileSystemProvider.SetSecurityDescriptor(String path, ObjectSecurity sd, AccessControlSections sections)
at Microsoft.PowerShell.Commands.FileSystemProvider.SetSecurityDescriptor(String path, ObjectSecurity securityDescriptor)
at System.Management.Automation.SessionStateInternal.SetSecurityDescriptor(CmdletProvider providerInstance, String path, ObjectSecurity
securityDescriptor, CmdletProviderContext context)
HelpLink :
Source : mscorlib
HResult : -2146233079
PS N:\WERVEN> $error[0].exception.innerexception| select *
PS N:\WERVEN>
编辑 11 月 22 日 - 第 2 部分
在 Synology nas 上分配权限似乎存在一些“已知”问题:http://mikebeach.org/2014/12/06/acl-fix-for-synology-diskstations/
因为我在这方面浪费了太多时间,所以我通过使用 ROBOCOPY 扩展我的脚本以将每个文件夹的文件夹移动到本地磁盘来解决我的问题。在这个本地磁盘上,我修复了权限并将 /MOVE /SEC /E 文件夹返回到 NAS。
占用更多时间.. 但它的工作原理。我可以睡一觉了。
【问题讨论】:
-
在你得到错误之后,你能不能执行以下操作并发布输出:
$error[0].exception|select *; $error[0].exception.innerexception| select *。如果在您的问题发生和您执行上述命令之间发生另一个错误,则 $error[0] 将不再涉及该问题。 $error[0] 总是最新的错误。 -
HResult 是
0x80131509 UIA_E_INVALIDOPERATION Indicates that the method attempted an operation that was not valid.- 不幸的是,它不是真正的新信息,除了它来自 UI 自动化(仅证实您的观察)。不知道...
标签: powershell