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”}
else
{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
}

#End

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: