# encoding: ascii
# api: powershell
# title: Backup-ModifiedGPOs
# description: All Group Policy Objects modified in the specified timespan are backup up to the specified backup path.
# version: 1.0
# type: script
# author: Jan Egil Ring
# license: CC0
# x-poshcode-id: 1914
# x-archived: 2016-06-01T12:26:28
# x-published: 2011-06-14T16:53:00
#
# For more details, see the following blog-post: 
# http://blog.powershell.no/2010/06/15/backing-up-group-policy-objects-using-windows-powershell
#
###########################################################################"
#
# NAME: Backup-ModifiedGPOs.ps1
#
# AUTHOR: Jan Egil Ring
# EMAIL: jan.egil.ring@powershell.no
#
# COMMENT: All Group Policy Objects modified in the specified timespan are backup up to the specified backup path.
#          For more details, see the following blog-post: 
#          http://blog.powershell.no/2010/06/15/backing-up-group-policy-objects-using-windows-powershell
#
# You have a royalty-free right to use, modify, reproduce, and
# distribute this script file in any way you find useful, provided that
# you agree that the creator, owner above has no warranty, obligations,
# or liability for such use.
#
# VERSION HISTORY:
# 1.0 15.06.2010 - Initial release
#
###########################################################################"

#Requires -Version 2.0

Import-Module grouppolicy

$BackupPath = "C:\GPO Backup"
$ReportPath = "C:\GPO Backup\Reports\"
$Timespan = (Get-Date).AddDays(-1)
$ModifiedGPOs = Get-GPO -all | Where-Object {$_.ModificationTime -gt $Timespan} 


Write-Host "The following "$ModifiedGPOs.count" GPOs were successfully backed up:" -ForegroundColor yellow

Foreach ($GPO in $ModifiedGPOs) { 

    $GPOBackup = Backup-GPO $GPO.DisplayName -Path $BackupPath
    $Path = $ReportPath + $GPO.ModificationTime.Month + "-"+ $GPO.ModificationTime.Day + "-" + $GPO.ModificationTime.Year + "_" +  

$GPO.Displayname + "_" + $GPOBackup.Id + ".html" 
    Get-GPOReport -Name $GPO.DisplayName -path $Path -ReportType HTML

    Write-Host $GPO.DisplayName
}
