In this article, we will prepare a report with powershell script in active directory environment.
What will be in the content of this report.
- Forest Name
- Domains
- Forest Functional Level
- Global Catalogs
- Recycle Bin
- Sites
- Duplicate SPN
- Duplicated DNS Zones (Forest)
- Duplicated DNS Zones (Domain)
I am sharing an example screenshot

The script used is as follows
# ===================================
# MSFTADVOCATE.COM REPORTS SCRIPT
# ===================================
Import-Module ActiveDirectory
# Gather AD Information
$forest = Get-ADForest
$domain = Get-ADDomain
$forestName = $forest.Name
$domains = ($forest.Domains) -join ", "
$forestFunctionalLevel = $forest.ForestMode
$globalCatalogs = ($forest.GlobalCatalogs) -join ", "
$sites = (Get-ADReplicationSite | Select-Object -ExpandProperty Name) -join ", "
# Check Recycle Bin Status
$recycleBinStatus = if ($forest.RecycleBinEnabled) { "Enabled" } else { "Not Enabled" }
# Check for Duplicate SPNs
$duplicateSPN = (Get-ADObject -Filter 'servicePrincipalName -like "*"' -Properties servicePrincipalName |
Select-Object -ExpandProperty servicePrincipalName | Group-Object | Where-Object { $_.Count -gt 1 })
if ($duplicateSPN) {
$duplicateSPNResult = "Found $($duplicateSPN.Count) group(s) of duplicate SPNs."
} else {
$duplicateSPNResult = "Found 0 group of duplicate SPNs."
}
# Placeholder for DNS Duplicate Zones (Advanced logic can be added)
$duplicateDNSForest = 0
$duplicateDNSDomain = 0
# Get Current Date and Time
$date = Get-Date -Format "yyyy-MM-dd HH:mm"
# Generate HTML Report
$report = @"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Active Directory Domain Services (AD DS) Report</title>
<style>
body {font-family: Arial, sans-serif; background-color: #f4f4f4; color: #333; padding: 20px;}
.container {max-width: 900px; margin: auto; background-color: white; padding: 30px;
border-radius: 10px; box-shadow: 0 0 15px rgba(0,0,0,0.2);}
h1 {text-align: center; color: #0078D7;}
p {text-align: center; color: #555;}
table {width: 100%; border-collapse: collapse; margin-top: 20px;}
th {background-color: #002147; color: white; text-align: left; padding: 12px; font-size: 16px;}
td {background-color: #f9f9f9; padding: 12px; border-bottom: 1px solid #ddd;}
.status-red {background-color: #ff4c4c; color: white; font-weight: bold;}
.status-green {background-color: #3cb371; color: white; font-weight: bold;}
</style>
</head>
<body>
<div class="container">
<h1>Active Directory Domain Services (AD DS) Report</h1>
<p>Generated on $date</p>
<table>
<tr><th>Property</th><th>Value</th></tr>
<tr><td>Forest Name</td><td>$forestName</td></tr>
<tr><td>Domains</td><td>$domains</td></tr>
<tr><td>Forest Functional Level</td><td>$forestFunctionalLevel</td></tr>
<tr><td>Global Catalogs</td><td>$globalCatalogs</td></tr>
<tr><td>Recycle Bin Status</td><td class="$(if($recycleBinStatus -eq 'Not Enabled'){'status-red'}else{'status-green'})">$recycleBinStatus</td></tr>
<tr><td>Sites</td><td>$sites</td></tr>
<tr><td>Duplicate SPN Check</td><td class="status-green">$duplicateSPNResult</td></tr>
<tr><td>Duplicated DNS Zones (Forest)</td><td class="status-green">$duplicateDNSForest</td></tr>
<tr><td>Duplicated DNS Zones (Domain)</td><td class="status-green">$duplicateDNSDomain</td></tr>
</table>
</div>
</body>
</html>
"@
# Save the HTML Report
$path = "C:\AD_DS_Report.html"
$report | Out-File -FilePath $path -Encoding utf8
Write-Host "HTML report has been generated: $path" -ForegroundColor Cyan
Start-Process $path