【问题标题】:Exception calling ".ctor" with 5 arguments among other errors使用 5 个参数调用“.ctor”的异常以及其他错误
【发布时间】: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


【解决方案1】:

您必须更改处理返回的经理数据的方式。您必须先查找管理器对象的 SamAccountNameSecurityIdentitifer 值,然后再将其传递给 FileSystemAccessRule()

$Employee = Get-ADUser -Identity test_Person -Properties Manager
$Manager = Get-ADUser -Identity $Employee.Manager | Select-Object -ExpandProperty SamAccountName
$Drive = "\\Sharename\directory"
$ACL = Get-Acl "$Drive\$($Employee.SamAccountName)"

$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($Manager, "FullControl", "containerInherit,ObjectInherit", "None", "Allow")
$ACL.SetAccessRule($Ar)
Set-Acl "$Drive\$($Employee.SamAccountName)" $ACL

在您的尝试中,$Manager 为空,因为默认情况下Get-ADUser 不返回 Manager 属性。您必须将其包含在-Property Manager 中。其次,manager 属性返回 manager 对象的 DN。 FileSystemAccessRule() 接受从 SamAccountNameSID 派生的 IdentityReference 对象,这意味着您必须执行转换或其他查找以获取正确的数据格式。

【讨论】:

    猜你喜欢
    • 2016-10-18
    • 2014-01-02
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    • 2019-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多