Why does Set-Acl on the drive root try to set ownership of the “object”?

后端 未结 5 1914
一向
一向 2020-12-07 22:45

I would like to change the ACL of the C: drive. What im trying to do is remove the permission that a user can create a folder directly on the drive. I tested th

5条回答
  •  情话喂你
    2020-12-07 23:21

    The below code works for me:

    $ApplicationPoolIdentity = "everyone"
    
    function SetACL()
    {
        param (
            [Parameter(Mandatory=$true)]
            [string]        $Path 
        )
    
        $Acl = (Get-Item $Path).GetAccessControl('Access')
        Write-Host "Path:" $Path "ID:" $ApplicationPoolIdentity
        $Ar = New-Object  system.security.accesscontrol.filesystemaccessrule($ApplicationPoolIdentity,"Write","Allow")
        $Acl.SetAccessRule($Ar)
        Write-Host $Acl
        $Acl | Set-Acl $Path
    }
    
    SetACL "C:\Test\"
    

提交回复
热议问题