windows - 如何使用 powershell 4.0 set-acl 允许用户在新创建的子目录中具有相同的安全设置?

标签 windows powershell server

当我通过 set-acl 设置用户访问权限时,我可以遍历所有现有的子文件夹。如何将其设置为包括以后在主文件夹下创建的子文件夹?

此外... 一旦设置了访问权限,它只会显示在文件夹的“高级”设置中。第一个安全屏幕显示用户但没有访问权限。

这是在 Windows Server 2012 R2 中。

$SubFolder = "name"
$UserName = "domain\" + $SubFolder
$Folder = "R:\User Files\" + $SubFolder + "\"

$Acl = Get-Acl $Folder
$Ar = New-Object system.security.accesscontrol.filesystemaccessrule($UserName,"FullControl","Allow")
$Acl.SetAccessRule($Ar)
#Get-Variable
Set-Acl -Path $Folder -AclObject $Acl

$Folder = Get-childItem $Folder
foreach ($TempFolder in $Folder)
{
    $Folder = $TempFolder.FullName
    $Acl = Get-Acl $Folder
    $Ar = New-Object    system.security.accesscontrol.filesystemaccessrule($UserName,"FullControl","Allow")
    $Acl.SetAccessRule($Ar)
    #Get-Variable
    Set-Acl -Path $Folder -AclObject $Acl
}

最佳答案

您需要设置继承和传播标志,以使其影响目标中的文件和文件夹。这是我在为用户设置新 ACL 时使用的典型模板:

$Rights = [System.Security.AccessControl.FileSystemRights]"FullControl" 

$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]"ObjectInherit,ContainerInherit"
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None 

$objType =[System.Security.AccessControl.AccessControlType]::Allow 

#Define the user's account using their samAccountName
$objUser = New-Object System.Security.Principal.NTAccount("samAccountName") 

$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule($objUser, $Rights, $InheritanceFlag, $PropagationFlag, $objType) 

$objACL = Get-ACL "C:\Temp" 

$objACL.AddAccessRule($objACE) 

Set-ACL "C:\Temp" $objACL

此处的设置将使 future 的东西继承您为目标文件夹定义的设置。

关于windows - 如何使用 powershell 4.0 set-acl 允许用户在新创建的子目录中具有相同的安全设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35807451/

相关文章:

windows - 在 Windows 中为文件名添加数字后缀

windows - 批处理文件 - 拖放 INTO 控制台窗口?

php - 在MySql中动态创建数据库并设置权限

java - 如何在 Openfire 上接收消息传递回执?

ios - 是否可以将应用程序的数据存储在用户的 Apple 帐户中?

linux - 管理本地用户帐户

python - Python 的图标覆盖问题

powershell - 如何删除空格并仅显示文本(如awk)?

c++ - 在没有测试框架的情况下使用 C++ 在 Appveyor 中运行测试

visual-studio - Visual Studio 2019 CE Powershell 项目