Created
May 1, 2023 14:06
-
-
Save aaronparker/61c803237b5c7b2a1d17b5b47b5a54ae to your computer and use it in GitHub Desktop.
Export GPO objects from a lab/test domain and zip
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
<# | |
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