Today one of my tasks was to remove some group policies.
Before I delete those, I always create a backup. Since the list of GPO’s was quite extensive, I turned to PowerShell.
Note that depending on your PowerShell version you may need to import the GroupPolicy module first by running:
Import-Module GroupPolicy
Now that’s done, I create a file with all the names of the GPO’s in there. You could type it manually, but I use PowerShell again.
To get the names of all the Group Policy Objects and put that list in the clipboard:
Get-GPO -All | Select-Object -ExpandProperty DisplayName | clip.exe
Now paste this list into a textfile and remove the ones you don’t want to create a backup from.
Then we get to the actual task… Backing up the GPO’s:
Get-Content c:\temp\gpos.txt | foreach { Get-GPO -Name "$_" | Backup-GPO -Path "D:\Backup" -Comment "$_" }
And as Jaap Brasser pointed out on Twitter, here’s the oneliner to backup all GPO’s without using the text file as input:
Get-GPO -All | foreach { Backup-GPO -Name $_.DisplayName -Path "D:\Backup" -Comment $_.DisplayName }