Forum Discussion
Policy Analyzer - Compare all settings
- Jun 28, 2023Policy Analyzer analyzes GPO backups, so a setting needs to be configured in one or more GPOs for it to show in a comparison.
Here's am example script that demonstrates how you can accomplish this:
# Define the names of the GPOs to compare
$referenceGPO = "ReferenceGPO"
$backupGPO = "BackupGPO"
# Get the policies from the reference GPO
$referencePolicies = Get-GPO -Name $referenceGPO | Get-GPOReport -ReportType Xml | Select-Xml -XPath "//GPO/ComputerConfiguration/Settings/*"
# Get the policies from the backup GPO
$backupPolicies = Get-GPO -Name $backupGPO | Get-GPOReport -ReportType Xml | Select-Xml -XPath "//GPO/ComputerConfiguration/Settings/*"
# Compare the policies
$addedPolicies = Compare-Object -ReferenceObject $referencePolicies -DifferenceObject $backupPolicies -Property Name -PassThru | Where-Object { $_.SideIndicator -eq "=>" }
$removedPolicies = Compare-Object -ReferenceObject $referencePolicies -DifferenceObject $backupPolicies -Property Name -PassThru | Where-Object { $_.SideIndicator -eq "<=" }
# Display the added policies
Write-Host "Added Policies:"
$addedPolicies | ForEach-Object { Write-Host $_.Name }
# Display the removed policies
Write-Host "Removed Policies:"
$removedPolicies | ForEach-Object { Write-Host $_.Name }
```
In this script, you need to replace "ReferenceGPO" and "BackupGPO" with the actual names of the GPOs you want to compare. The script retrieves the policies of each GPO using `Get-GPO` and `Get-GPOReport` cmdlets. Then, it compares the policies using `Compare-Object` and filters the added and removed policies based on the `SideIndicator` property.
The added policies are displayed first, followed by the removed policies. You can modify the script to suit your specific requirements, such as comparing user configuration policies or exporting the results to a file.
Note: The script compares the policies at the computer configuration level. If you want to compare user configuration policies, you can modify the XPath expression to "//GPO/UserConfiguration/Settings/*".
- AaronMargosis_TaniumJun 28, 2023Iron ContributorThat will perform a very simplistic comparison of the GPOs. Policy Analyzer understands the contents of GPOs to a much deeper level than what Compare-Object can do.
- jemfernandezJun 28, 2023Copper ContributorHi LeonPavesic
Thank you for sharing the script. This is very much appreciated.
Get-GPOReport will only show applied policy settings. I would like to have all policies around 3000+ (including applied and not applied) to be displayed. Is it possible?
Thank you in advance.- AaronMargosis_TaniumJun 28, 2023Iron ContributorPolicy Analyzer analyzes GPO backups, so a setting needs to be configured in one or more GPOs for it to show in a comparison.
- jemfernandezJun 28, 2023Copper ContributorThank you AaronMargosis_Tanium. I agree but I would like to display all without configuring each setting. I am hoping there's a way either Policy Analyzer or other tools like PowerShell.