DEV Community

Thiyagarajan Thangavel
Thiyagarajan Thangavel

Posted on

Script for GP result Comparison

Define paths to the two GPResult HTML files

$File1 = "C:\Reports\GPResult1.html"
$File2 = "C:\Reports\GPResult2.html"

Load HTML content

$Html1 = Get-Content $File1 -Raw
$Html2 = Get-Content $File2 -Raw

Convert HTML to XML

[xml]$Xml1 = $Html1
[xml]$Xml2 = $Html2

Helper function to extract GPOs and settings

function Get-GPODataFromHtml($Xml) {
$tables = $Xml.getElementsByTagName("table")
$gpoTable = $tables | Where-Object { $.innerText -like "Applied Group Policy Objects" }
$settingTables = $tables | Where-Object { $
.innerText -match "Security Settings|Registry|Scripts|Folder Redirection" }

$gpoList = @()
$settingList = @()

if ($gpoTable.Count -gt 0) {
    $rows = $gpoTable[0].getElementsByTagName("tr")
    foreach ($row in $rows) {
        $cells = $row.getElementsByTagName("td")
        if ($cells.Count -gt 0) {
            $gpoList += $cells[0].innerText.Trim()
        }
    }
}

foreach ($table in $settingTables) {
    $rows = $table.getElementsByTagName("tr")
    foreach ($row in $rows) {
        $cells = $row.getElementsByTagName("td")
        if ($cells.Count -ge 2) {
            $settingList += "$($cells[0].innerText.Trim()) = $($cells[1].innerText.Trim())"
        }
    }
}

return @{GPOs = $gpoList; Settings = $settingList}
Enter fullscreen mode Exit fullscreen mode

}

Extract data

$Data1 = Get-GPODataFromHtml $Xml1
$Data2 = Get-GPODataFromHtml $Xml2

Compare GPOs

$GPOsOnlyIn1 = Compare-Object $Data1.GPOs $Data2.GPOs -PassThru | Where-Object { $.SideIndicator -eq "<=" }
$GPOsOnlyIn2 = Compare-Object $Data1.GPOs $Data2.GPOs -PassThru | Where-Object { $
.SideIndicator -eq "=>" }

Compare Settings

$SettingsOnlyIn1 = Compare-Object $Data1.Settings $Data2.Settings -PassThru | Where-Object { $.SideIndicator -eq "<=" }
$SettingsOnlyIn2 = Compare-Object $Data1.Settings $Data2.Settings -PassThru | Where-Object { $
.SideIndicator -eq "=>" }

Output differences

Write-Host "`n🔍 GPOs only in File 1:"
$GPOsOnlyIn1 | ForEach-Object { Write-Host " - $_" }

Write-Host "`n🔍 GPOs only in File 2:"
$GPOsOnlyIn2 | ForEach-Object { Write-Host " - $_" }

Write-Host "`n🔧 Settings only in File 1:"
$SettingsOnlyIn1 | ForEach-Object { Write-Host " - $_" }

Write-Host "`n🔧 Settings only in File 2:"
$SettingsOnlyIn2 | ForEach-Object { Write-Host " - $_" }

Optional: Export to CSV

$Report = @()
foreach ($item in $SettingsOnlyIn1) {
$Report += [PSCustomObject]@{Source="File1"; Setting=$item}
}
foreach ($item in $SettingsOnlyIn2) {
$Report += [PSCustomObject]@{Source="File2"; Setting=$item}
}
$Report | Export-Csv "C:\Reports\GPO_Differences.csv" -NoTypeInformation
Write-Host "`n📁 Differences exported to C:\Reports\GPO_Differences.csv"

Top comments (0)