PoshCode Logo PowerShell Code Repository

Backup-ModifiedGPOs by Jan Egil Ring 6 years ago
View followups from Andy Helsby | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1914"></script>download | new post

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

  1. ###########################################################################"
  2. #
  3. # NAME: Backup-ModifiedGPOs.ps1
  4. #
  5. # AUTHOR: Jan Egil Ring
  6. # EMAIL: jan.egil.ring@powershell.no
  7. #
  8. # COMMENT: All Group Policy Objects modified in the specified timespan are backup up to the specified backup path.
  9. #          For more details, see the following blog-post:
  10. #          http://blog.powershell.no/2010/06/15/backing-up-group-policy-objects-using-windows-powershell
  11. #
  12. # You have a royalty-free right to use, modify, reproduce, and
  13. # distribute this script file in any way you find useful, provided that
  14. # you agree that the creator, owner above has no warranty, obligations,
  15. # or liability for such use.
  16. #
  17. # VERSION HISTORY:
  18. # 1.0 15.06.2010 - Initial release
  19. #
  20. ###########################################################################"
  21.  
  22. #Requires -Version 2.0
  23.  
  24. Import-Module grouppolicy
  25.  
  26. $BackupPath = "C:\GPO Backup"
  27. $ReportPath = "C:\GPO Backup\Reports\"
  28. $Timespan = (Get-Date).AddDays(-1)
  29. $ModifiedGPOs = Get-GPO -all | Where-Object {$_.ModificationTime -gt $Timespan}
  30.  
  31.  
  32. Write-Host "The following "$ModifiedGPOs.count" GPOs were successfully backed up:" -ForegroundColor yellow
  33.  
  34. Foreach ($GPO in $ModifiedGPOs) {
  35.  
  36.     $GPOBackup = Backup-GPO $GPO.DisplayName -Path $BackupPath
  37.     $Path = $ReportPath + $GPO.ModificationTime.Month + "-"+ $GPO.ModificationTime.Day + "-" + $GPO.ModificationTime.Year + "_" +  
  38.  
  39. $GPO.Displayname + "_" + $GPOBackup.Id + ".html"
  40.     Get-GPOReport -Name $GPO.DisplayName -path $Path -ReportType HTML
  41.  
  42.     Write-Host $GPO.DisplayName
  43. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me