Skip to content

Instantly share code, notes, and snippets.

@aaronparker
Created May 1, 2023 14:06
Show Gist options
  • Save aaronparker/61c803237b5c7b2a1d17b5b47b5a54ae to your computer and use it in GitHub Desktop.
Save aaronparker/61c803237b5c7b2a1d17b5b47b5a54ae to your computer and use it in GitHub Desktop.
Export GPO objects from a lab/test domain and zip
<#
Export GPO objects from a lab/test domain and zip
#>
# Local path over RDP connection
$Destination = "C:\Backup"
# Create backups, zip file and copy to client path
$Path = "C:\Temp\Prod-GPO"
$Domain = "home.stealthpuppy.com"
$Server = "dc1.home.stealthpuppy.com"
New-Item -Path $Path -ItemType Directory -ErrorAction "SilentlyContinue"
Get-GPO -All | Where-Object { $_.displayName -match "^Prod-RDS*" } | Backup-GPO -Path $Path -Domain $Domain -Server $Server
# Unhide required files because Compress-Archive doesn't include hidden files
Get-ChildItem -Path $Path -Recurse -Hidden -Include "*.xml" | ForEach-Object { attrib -h $_.FullName }
Compress-Archive -Path $Path -DestinationPath "C:\Temp\Prod-GPO-backup.zip"
Copy-Item -Path "C:\Temp\Prod-GPO-backup.zip" -Destination "$Destination\Prod-GPO-backup.zip" -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment