Powershell 跨多个文件夹应用权限

Powershell 跨多个文件夹应用权限,powershell,windows-server,icacls,Powershell,Windows Server,Icacls,我需要创建一个脚本,该脚本将在许多文件夹上应用权限,根据文件夹名称具有不同的权限。有一个根文件夹共享,其中有一个代表每个客户端的文件夹。每个客户机文件夹内都有一个部门文件夹。我需要按安全组限制对每个部门文件夹的访问,以便只有属于该部门的人员才能访问它们 情况如下: ROOT FOLDER SHARE | |-----CLIENT1 (everyone has access) |.......|------DEPARTMENT1 (only members of department1

我需要创建一个脚本,该脚本将在许多文件夹上应用权限,根据文件夹名称具有不同的权限。有一个根文件夹共享,其中有一个代表每个客户端的文件夹。每个客户机文件夹内都有一个部门文件夹。我需要按安全组限制对每个部门文件夹的访问,以便只有属于该部门的人员才能访问它们

情况如下:

ROOT FOLDER SHARE  
|  
|-----CLIENT1 (everyone has access)  
|.......|------DEPARTMENT1 (only members of department1 have access)  
|.......|------DEPARTMENT2 (only members of department2 have access)  
|.......|------DEPARTMENT3 (only members of department3 have access)  
|  
|-----CLIENT2 (everyone has access)  
|.......|------DEPARTMENT1 (only members of department1 have access)  
|.......|------DEPARTMENT2 (only members of department2 have access)  
|.......|------DEPARTMENT3 (only members of department3 have access)  
|  
|-----CLIENT3 (everyone has access)  
........|------DEPARTMENT1 (only members of department1 have access)  
........|------DEPARTMENT2 (only members of department2 have access)  
........|------DEPARTMENT3 (only members of department3 have access)  
我不完全确定如何正确地实现这一点。有人能帮我指出正确的方向吗?这是在运行Windows server 2008 R2和active directory安装程序的服务器上

我目前拥有的是这样的(看起来很有效):


您可以使用Set ACL命令使用PowerShell自动化权限设置

有一篇好文章可以帮助你完成这项任务


到目前为止,您尝试了什么?你到底被卡在哪里了?向我们展示,您已经投入了一些努力,试图将一个工作脚本组合在一起。
$Path = Read-Host "What is the starting path?"
$DirectoryName = Read-Host "What is the name of the directory?"
$SecurityGroup = Read-Host "What is the name of the security group that will be given permissions on these directories?"
$ListOfDirectories = Get-ChildItem $Path -Recurse | Where-Object { $_.PSIsContainer } | Where-Object { $_.name -eq $DirectoryName } | foreach-object -process { $_.FullName }

foreach ($directory in $ListOfDirectories) {
    icacls.exe $directory /grant ""$SecurityGroup":M" /t
}