Skip to content

Instantly share code, notes, and snippets.

@aaronparker
Created May 1, 2023 14:06
Show Gist options
  • Save aaronparker/8a3dd165f32604cd47ba4b13fd1c90a5 to your computer and use it in GitHub Desktop.
Save aaronparker/8a3dd165f32604cd47ba4b13fd1c90a5 to your computer and use it in GitHub Desktop.
Import GPO backups into a new domain
# 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