Created
May 1, 2023 14:06
-
-
Save aaronparker/8a3dd165f32604cd47ba4b13fd1c90a5 to your computer and use it in GitHub Desktop.
Import GPO backups into a new domain
This file contains 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
# Import Group Policy Objects | |
$Path = "C:\Temp" | |
$Destination = "C:\Temp\Prod-GPO" | |
Expand-Archive -Path "$Path\Prod-GPO-backup.zip" -DestinationPath $Path | |
$BackupList = Get-ChildItem -Path $Destination -Directory -Exclude "manifest.xml" | |
foreach ($item in $BackupList) { | |
[System.Xml.XmlDocument] $XmlFile = Get-Content -Path "$($item.FullName)\gpreport.xml" -ErrorAction "Stop" | |
$BackupID = $item.Name -replace "{|}", "" | |
$BackupID = $item.Name -replace "{", "" -replace "}", "" | |
$GpoName = "Test-$($XmlFile.GPO.Name)" | |
Import-GPO -BackupId $BackupID -TargetName $GpoName -Path $Destination -CreateIfNeeded -Verbose | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment