Not a lot of exposition on this one.
I have a client that has 100+ Group Policy Objects that I wanted to export. Now in the time I was developing a way to automatically do this, I probably could have right clicked each and exported, but that’s no fun and I can use this script in the future.
General Script Notes
- Change $folderpath variable to an existing folder path, this script will not create the folder structure, but if you want to add that, feel free
- the last line will go through this entire folder and rename with a new file extension, xml or html, depending on which script you are running. Please use a clean and empty folder for this. If there is anything else in the folder, it will get the filetype changed!
Powershell script to export all GPOs to XML
$folderpath = "C:\path\to\existing\folder\"
$AllGpos = get-gpo -all
ForEach($g in $AllGpos)
{
$filename = $g.DisplayName
$fullpath = join-path -path $folderpath -ChildPath $filename
$Gpo = Get-GPOReport -reporttype xml -guid $g.Id -path $fullpath
}
get-childitem -path $folderpath | Rename-Item -NewName { $PSItem.Name + ".xml" }
Powershell script to export all GPOs to HTML
$folderpath = "C:\path\to\existing\folder\"
$AllGpos = get-gpo -all
ForEach($g in $AllGpos)
{
$filename = $g.DisplayName
$fullpath = join-path -path $folderpath -ChildPath $filename
$Gpo = Get-GPOReport -reporttype html -guid $g.Id -path $fullpath
}
get-childitem -path $folderpath | Rename-Item -NewName { $PSItem.Name + ".html" }
That’s all for today!
Thanks so much – this helped immensely.