New-GPOBackup.ps1

# New-GPOBackup.ps1
# Writen By Brandon Shell (www.BSonPosh.com)
# Creates a New Backup for a GPO or ALL if none are specified
# Parameters
#  -Path: Path for the backup folder REQUIRED
#  -GPOName: Name of the GPO
# Switches
#  -Date: Creates a Subfolder Under Backup Path for the Date
#  -Verbose: Enables Verbose Logging
# Requires Set-GPEnvironment.ps1
Param($Path = $(throw '$Path is Require'),
      $GPOName,
      [switch]$date,
      [switch]$Verbose)
if($verbose){$verbosepreference = "continue"}
. "$pwd\Set-GPEnvironment.ps1"
Write-Host
$GPOs = $gpmDomain.SearchGPOs($gpm.CreateSearchCriteria())

if($GPOName)
{
    $GPOs = $GPOs | Where-Object{$_.DisplayName -eq $GPOName}
}

if($date)
{
    $backupPath = "{0}\{1:yyyyMMdd}" -f $Path,(Get-Date)
    if(!(test-Path $backupPath))
    {
        New-Item $backupPath -type Directory -force | out-Null
    }
}
else
{
    $backupPath = $path
    if(!(test-Path $backupPath))
    {
        New-Item $backupPath -type Directory -force | out-Null
    }
}

foreach($gpo in $gpos)
{
    write-Host "Backing Up <$($GPO.DisplayName)> to <$backupPath>"
    $gpo.Backup($backupPath,$null,$null) | out-null
}
Write-Host

Attachments:
 New-GPOBackup.txt- New-GPOBackup.ps1 script referenced in Chapter 11. Please change file extension from .txt to .ps1
 

Be a hero! Report a problem with this web page here

Event Calendar

Find out where and when Jeremy will be speaking next.

November 2008
SMTWTFS
1
2345678
9101112131415
16171819202122
23242526272829
30
Mon, Nov 10 - Thu, Nov 13
Windows Connections -- Vegas
It's WinConnections time! All sorts of great speeches this time. GP Troubleshooting, My Pre-Con, App-V 101. Will you be there?
www.winconnections.com
Mon, Nov 17 - Tue, Nov 18
Two-Day Intensive Group Policy Essentials Workshop (taught by Jeremy Moskowitz (Lead Instructor) - GPanswers.com / Moskowitz, Inc. )
 Final class of 2008.
This is a Two-Day Intensive Group Policy Essentials Workshop in Atlanta, GA !
Wed, Nov 19 - Thu, Nov 20
Two-Day "Group Policy 2.0" Catch-Up Workshop (taught by Jeremy Moskowitz (Lead Instructor) - GPanswers.com / Moskowitz, Inc. )
 Final class of 2008.
This is a Two-Day "Group Policy 2.0" Catch-Up Workshop in Atlanta, GA !
Fri, Nov 21 - Fri, Nov 21
One-Day Advanced Group Policy Workshop (XP/Vista Focused) (taught by Jeremy Moskowitz (Lead Instructor) - GPanswers.com / Moskowitz, Inc. )
 Final class of 2008.
This is a One-Day Advanced Group Policy Workshop (XP/Vista Focused) in Atlanta, GA !