Created
October 17, 2018 11:33
-
-
Save techdecline/213e8a9582fbdef515e9d840bf86cc67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| param ( | |
| [String]$GpoBackupFolder = "E:\Sources\Security Baseline\Windows-10-RS4-Security-Baseline-FINAL\GPOs", | |
| [String]$DomainName = "decline.lab", | |
| [String]$PilotOU = "OU=Security Baseline 1803,OU=Workstations,DC=decline,DC=lab" | |
| ) | |
| function Get-GpoNameFromReport { | |
| param ( | |
| [Parameter(Mandatory)] | |
| [String]$GpoReportPath | |
| ) | |
| $reportXml = $GpoReportPath | |
| $xmlDoc = [System.Xml.XmlDocument]::new() | |
| $xmlDoc.Load($reportXml) | |
| $gpoName = $xmlDoc.GPO.Name | |
| return $gpoName | |
| } | |
| $gpoArr = Get-ChildItem $GpoBackupFolder -Directory | |
| foreach ($gpoExport in $gpoArr) { | |
| $reportXmlFile = Get-ChildItem -Path $gpoExport.FullName -Filter "gpreport.xml" | |
| $gpoName = Get-GpoNameFromReport -GpoReportPath $reportXmlFile.FullName | |
| $newGpoObject = New-GPO -Name $gpoName -Domain $domainName -Comment "Imported from $GpoBackupFolder on $(Get-Date -Format yyyyMMdd) by $env:USERNAME" | |
| Import-GPO -Path $GpoBackupFolder -TargetName $gpoName -Domain $DomainName -BackupId $gpoExport.Name | |
| if ($PilotOU) { | |
| New-GPLink -Guid $newGpoObject.id -Target $PilotOU -LinkEnabled Yes -Domain $DomainName | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment