To fetch all Active Directory Group Policy Objects (GPOs) and export them to an HTML report that includes details for all GPOs, you can use the following PowerShell script:
# Define the target OU where you want to retrieve GPO links
$targetOU = "OU=YourTargetOU,DC=YourDomain,DC=com"
# Get all Group Policy Objects
$allGPOs = Get-GPO -All
# Create an array to store GPO details
$gpoDetails = @()
# Loop through each GPO and retrieve details
foreach ($gpo in $allGPOs) {
$gpoInfo = @{
'DisplayName' = $gpo.DisplayName
'Id' = $gpo.Id
'Description' = $gpo.Description
'CreationTime' = $gpo.CreatedTime
'ModificationTime' = $gpo.ModifiedTime
'Owner' = $gpo.Owner
'WmiFilter' = $gpo.WmiFilter
}
# Get GPO links for the target OU
$gpoLinks = (Get-GPInheritance -Target $targetOU -Verbose:$false | Where-Object { $_.Id -eq $gpo.Id }).GpoLinks
$gpoInfo['Links'] = $gpoLinks -join ', '
# Add GPO details to the array
$gpoDetails += New-Object PSObject -Property $gpoInfo
}
# Create an HTML report
$htmlReport = $gpoDetails | ConvertTo-Html -As Table -Fragment
# Save the HTML report to a file
$htmlReport | Out-File -FilePath "GPOs_Report.html"
Write-Host "Group Policy Objects report for $targetOU has been saved as GPOs_Report.html"
This script does the following:
- Retrieves all Group Policy Objects using
Get-GPO -All
. - Loops through each GPO and collects details such as DisplayName, Id, Description, CreationTime, ModificationTime, Owner, WmiFilter, SOM (Scope of Management), and Links.
- Creates an HTML report in table format using
ConvertTo-Html
. - Saves the HTML report to a file named “GPOs_Report.html” in the current directory.
Running this script will generate an HTML report that includes details for all GPOs in your Active Directory. You can customize the properties included in the report or the file path where the report is saved as needed.