新的PSDrive和Get-Acl权限

时间:2018-04-06 06:02:27

标签: powershell acl

我为没有权限的用户创建脚本,这将允许他们创建特定的文件夹结构并获得对它们的权限。 (只读)。 目标是:

  • 创建文件夹结构
  • Set-Acl只读该用户

为此,我创建了以下内容:

New-PSDrive -Name "target" -PSProvider "FileSystem" -Credential $cred -Root $cr | Out-Null

foreach ($pers in $persons) {
    $readOnly = [System.Security.AccessControl.FileSystemRights]"ReadAndExecute"

    # Inheritance
    $inheritanceFlag = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit, ObjectInherit"

    # Propagation
    $propagationFlag = [System.Security.AccessControl.PropagationFlags]::None

    # User
    $userR = New-Object System.Security.Principal.NTAccount($pers)

    # Type
    $type = [System.Security.AccessControl.AccessControlType]::Allow


    $accessControlEntryR = New-Object System.Security.AccessControl.FileSystemAccessRule @($userR, $readOnly, $inheritanceFlag, $propagationFlag, $type)
    $objACL = Get-ACL target:\$admin\$directie\$year\$dos_nr
    $objACL.AddAccessRule($accessControlEntryR)

    Set-ACL target:\$admin\$directie\$year\$dos_nr $objACL
}

Remove-PSDrive target

显然,我创建的PSDrive帐户具有对该文件夹结构的管理员级别访问权限。我登录到域的帐户,并使用(作为ISE中的管理员)执行脚本。

然而我仍然得到许可被拒绝错误。

关于我做错了什么的任何建议?

请求的确切错误:

  

Set-Acl:Poging tot het uitvoeren van een niet-gemachtigde bewerking。   在线:26 char:5   + Set-Acl -Path目标:\ $ admin \ $ directie \ $ year \ $ dos_nr -AclObject $ ...   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~       + CategoryInfo:PermissionDenied:(xxxxxxxxxx:String)[Set-Acl],UnauthorizedAccessException       + FullyQualifiedErrorId:System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetAclCommand

0 个答案:

没有答案
相关问题