Backup GPOs

# Import the modules that we need
import-module activedirectory
import-module grouppolicy

# Specify the location for the backups
$BackupPath = “C:\Backup\GPO\”

# Create the backup folder if it doesn’t exist
if(test-path -path $BackupPath)
{write-host “The folder” $BackupPath “already exists”}
{New-Item $BackupPath -type directory}

# Remove any previous backups from the folder
##  Note: You will need to move the backups off to tape/disk
##  archive daily if you need access to older GPO versions
Remove-Item $BackupPath\* -Recurse-Force

# Find out what domain this computer is in
$mydomain = get-ADDomain-currentLocalComputer

# Get all the GPOs in the specified domain
$AllDomGPOs = get-gpo -domain $mydomain.DNSRoot -all

# Loop through the array
Foreach ($GPO in $AllDomGPOs)
# Backup the GPO to the specified path
backup-GPO $GPO.DisplayName -path $BackupPath



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: