# Import the Group Policy module Import-Module GroupPolicy # Define the target folder path $reportFolder = "C:\temp\gpoReport" # Create the folder if it doesn't exist if (-Not (Test-Path $reportFolder)) { New-Item -ItemType Directory -Path $reportFolder -Force | Out-Null } # Fetch all GPOs $gpos = Get-GPO -All # Generate GPO reports foreach ($gpo in $gpos) { $reportPath = Join-Path -Path $reportFolder -ChildPath "$($gpo.DisplayName).xml" Get-GPOReport -Guid $gpo.Id -ReportType XML -Path $reportPath }
then process the XMLs
# Define the folder containing the XML files $xmlFolder = "C:\Users\....\gpoReport" # Ensure the folder exists if (-Not (Test-Path $xmlFolder)) { Write-Host "The folder does not exist: $xmlFolder" -ForegroundColor Red return } # Get all XML files in the folder $xmlFiles = Get-ChildItem -Path $xmlFolder -Filter "*.xml" # Process each XML file foreach ($file in $xmlFiles) { try { # Load the XML file $xml = [xml](Get-Content -Path $file.FullName) # Get GPO name $gpoName = $xml.GPO.Name Write-Host $gpoName -ForegroundColor Cyan # Parse Computer configuration settings if ($xml.GPO.Computer.Enabled -eq "true") { Write-Host " Computer Configuration" -ForegroundColor Yellow $majorPolicies = $xml.GPO.Computer.ExtensionData | Select-Object -ExpandProperty Name foreach ($policy in $majorPolicies) { Write-Host " $policy" -ForegroundColor Green } } # Parse User configuration settings if ($xml.GPO.User.Enabled -eq "true") { Write-Host " User Configuration" -ForegroundColor Yellow $majorPolicies = $xml.GPO.User.ExtensionData | Select-Object -ExpandProperty Name foreach ($policy in $majorPolicies) { Write-Host " $policy" -ForegroundColor Green } } # Parse Links $linkedOUs = $xml.GPO.LinksTo | ForEach-Object { "$($_.SOMName) ($($_.SOMPath))" } if ($linkedOUs.Count -gt 0) { foreach ($link in $linkedOUs) { Write-Host " Linked to: $link" -ForegroundColor Magenta } } else { Write-Host " Linked to: nothing" -ForegroundColor DarkGray } } catch { Write-Host "Error processing file $($file.FullName): $_" -ForegroundColor Yellow } }