我需要自动创build多个安全组,然后创build并应用包含OU /安全组特定文件权限和审核的GPO。
我已经完成了OU和组创build。 我可以将权限/审计作为ACL来执行,但是需要将其作为GPO应用。 我可以链接到OU /组,我可以复制现有的GPO,但是我仍然需要replace某些安全组。 我确实为每个安全组创build了registry项,但我找不到任何有关创build文件权限/审计的文档。
案例:我们推出分配给特定客户端的虚拟Web服务器。 我们有一个PS脚本,为新服务器创build新的OU和安全组。 如果我们需要重新部署虚拟机,而不是必须重新应用带有ACL的PS脚本,我们希望自动创build包含默认文件夹ACL的GPO,这样我们就不必在一旦虚拟机备份,重新部署。
我有ACL脚本,并且工作正常,但在这种情况下它不适合自动化。
因此,使用Powershell无法直接在GPO中设置文件权限。 (计算机/策略/ Windows设置/安全设置/文件系统)
但是,我可以通过创buildGPO并手动备份(一次性)来解决此问题。 关于我正在寻找的具体答案,有3个文件需要在GPO备份中进行编辑。
您将需要用占位符[GROUP_NAME]和[GROUP_SID](也可以是USER)的三个文件中的用户组名称和SIDreplace。 您还需要将gpreport.xml中的{Name}标记和backup.XML中的{DisplayName}更新为GPO的新名称。 我与另一个地点持有人[GPO_NAME]一起完成了此操作。
现在,这是棘手的一部分,花了一段时间才弄清楚。 你不能只是导入GPO这个新的对象。 实际上,您必须创build一个新的空白GPO,将其备份,然后将从模板更新的文件输出到此备份中。
这是我使用的代码。 这里有几个占位符。 根据需要replace您的环境。 它看起来像在PowerShell脚本上的堆栈格式是有点closures。 它作为粘贴。
#root path for script and files. $scriptPath = "c:\GPO_Deployment" # Create new GPO write-host "Create new GPO" new-GPO -Name [GPO_NAME] # Backup New GPO to Named folder $backup = backup-gpo -Name [GPO_NAME] -Path $scriptPath # # Files that need to be updated: # GPO_TEMPLATE_FILES\Backup.xml # GPO_TEMPLATE_FILES\gpreport.xml # GPO_TEMPLATE_FILES\DomainSysvol\GPO\Machine\microsoft\windows nt\SecEdit\GptTmpl.inf # Create Output file strucures $newXMLpath = New-Item -Path ("{" + $backup.Id + "}") -ItemType Directory -Force $newGPOinfPath = New-Item -ItemType Directory -Path ("{" + $backup.Id + "}\\DomainSysvol\\GPO\\Machine\\microsoft\\windows nt\\SecEdit") -Force #get the Group SIDS for the groups we created above $GROUP_SID = (New-Object System.Security.Principal.NTAccount("DOMAIN", [GROUP_NAME])).Translate([System.Security.Principal.SecurityIdentifier]) write-host "Applying tranforms to template files" # read inf_template file, replace sids, and write out $inf_template = join-path -Path ($scriptPath + "\GPO_TEMPLATE_FILES\DomainSysvol\GPO\Machine\microsoft\windows nt\SecEdit") -ChildPath "GptTmpl.inf" $inf_outfile = Join-Path -Path $newGPOinfPath -ChildPath "GptTmpl.inf" (Get-Content $inf_template) | ForEach-Object { $_ -replace '\[GROUP_SID\]', $GROUP_SID } | Set-Content $inf_outfile # read Backup XML template file, replace sids, and write out $backup_template = join-path -Path ($scriptPath + "\GPO_TEMPLATE_FILES") -ChildPath "Backup.xml" $backup_outfile = Join-Path -Path $newXMLpath -ChildPath "Backup.xml" (Get-Content $backup_template) | ForEach-Object { $_ -replace '\[GROUP_SID\]', $GROUP_SID ` -replace '\[GPO_NAME\]', $hostedclient } | Set-Content $backup_outfile # read GPO Report XML template file, replace sids, and write out $gporeport_template = join-path -Path ($scriptPath + "\GPO_TEMPLATE_FILES") -ChildPath "gpreport.xml" $gporeport_outfile = Join-Path -Path $newXMLpath -ChildPath "gpreport.xml" (Get-Content $gporeport_template) | ForEach-Object { $_ -replace '\[GROUP_SID\]', $GROUP_SID ` -replace '\[GPO_NAME\]', $hostedclient } | Set-Content $gporeport_outfile Write-Host "Saving updated GPO, linking it to the new OU and moving traget web server to new OU." # Import GPO import-gpo -BackupId $backup.Id -Path $scriptPath -TargetName [GPO_NAME] -CreateIfNeeded $updatedGPO = get-gpo -Name [GPO_NAME] # Link GPO to OU ## NOTE: If you are updating an existing GPO Link, use Set-GPLink here New-GPLink -Guid $updatedGPO.Id -Target ("OU=[YOUR_OU],DC=domain,DC=local") -LinkEnabled Yes # Move web server to OU get-adcomputer [YOUR_SERVER] | Move-ADObject -TargetPath ("OU=[YOUR_OU],DC=domain,DC=local") # Add another wait for GPO to settle before forcing update. Write-Host "Pausing again to allow DC to catch-up again." start-sleep -seconds 15 write-host "Forcing a GP Update on target webserver." Invoke-GPUpdate -Computer [YOUR_SERVER]
你必须在计算机configuration中做。 去:
计算机configuration\策略\ Windows设置\安全设置\文件系统
右键单击右窗格中的空白区域,然后select“添加文件”。 如果你所在的系统没有你想要的文件夹,你可以在这个文件浏览器中创build它。 select文件夹后,分配NTFS权限。