【发布时间】:2019-12-01 21:43:55
【问题描述】:
我正在创建一个脚本来自动化流程,但在设置网络共享权限时遇到了问题。请看下面的代码。
$Employee = Get-ADUser -Identity test_Person | Select-Object -ExpandProperty SamAccountName
$Manager = Get-ADUser -Identity test_Person | Select-Object -ExpandProperty Manager
$Drive = "\\Sharename\directory\"
$ACL = Get-Acl "$Drive\$($Employee)"
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($Manager, "FullControl", "containerInherit,ObjectInherit", "None", "Allow")
$ACL.SetAccessRule($Ar)
Set-Acl "$Drive\$($Employee)" $ACL
以下是错误。非常感谢任何帮助
New-Object:使用“5”个参数调用“.ctor”的异常:“值不能为空。 参数名称:身份" 在行:5 字符:7 + $Ar = 新对象 System.Security.AccessControl.FileSystemAccessRule($ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
使用“1”参数调用“SetAccessRule”的异常:“值不能为空。 参数名称:规则" 在行:6 字符:1 + $ACL.SetAccessRule($Ar) + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentNullException
Set-Acl:进程不具备此操作所需的“SeSecurityPrivilege”特权。 在行:7 字符:1 + 设置 Acl "$LDrive\$($Employee)" $ACL + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (\Drive\Directory\Test_Person:String) [Set-Acl], PrivilegeNotHeldException + FullyQualifiedErrorId : System.Security.AccessControl.PrivilegeNotHeldException,Microsoft.PowerShell.Commands.SetAclCommand
【问题讨论】:
-
这可能不是您的全部问题,但
$Manager为空,因为默认情况下Get-ADUser不返回 Manager 属性。您必须将其包含在-Property Manager中。其次,manager 属性返回 manager 对象的 DN。我不知道FileSystemAccessRule()是否接受 DN,或者它是否需要是 SamAccountName 或 SID。
标签: powershell