1

我有一个文件夹

C:\TEMP

里面有子文件夹

C:\TEMP\a C:\TEMP\b和一个文件名apple.txt

如何使用 powershell 脚本将所有权限更改为具有完全控制访问权限的所有人?

谢谢

4

2 回答 2

5
$user = "domain\user"
$Folders = Get-childItem c:\TEMP\
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$objType = [System.Security.AccessControl.AccessControlType]::Allow 

$Folders | %{
    $Folder = $_

    $acl = Get-Acl $Folder
    $permission = $user,"Modify", $InheritanceFlag, $PropagationFlag, $objType
    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission

    $acl.SetAccessRule($accessRule)
    Set-Acl $Folder $acl
} 
于 2013-02-27T07:37:10.600 回答
0

感谢您的回答。我做了一些更正和增强(关键字/预期模式)

$user = "everyone"
$Folders = Get-childItem -Directory F:\SITE\
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$objType = [System.Security.AccessControl.AccessControlType]::Allow 
$keyword = "PublicTempStorage"

$Folders | %{
    $Folder = $_

    $acl = Get-Acl $Folder.FullName
    $permission = $user,"Modify", $InheritanceFlag, $PropagationFlag, $objType
    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission

    $acl.SetAccessRule($accessRule)
    if ($Folder -match $keyword) 
    {
        Set-Acl -AclObject $acl -Path $Folder.FullName
    }
} 
于 2018-06-27T21:44:05.560 回答