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:

  1. Retrieves all Group Policy Objects using Get-GPO -All.
  2. Loops through each GPO and collects details such as DisplayName, Id, Description, CreationTime, ModificationTime, Owner, WmiFilter, SOM (Scope of Management), and Links.
  3. Creates an HTML report in table format using ConvertTo-Html.
  4. 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.

By amit_g

Welcome to my IT Infra Blog! My name is Amit Kumar, and I am an IT infrastructure expert with over 11 years of experience in the field. Throughout my career, I have worked with a wide variety of systems and technologies, from network infrastructure and cloud computing to hardware and software development. On this blog, I aim to share my knowledge, insights, and opinions on all things related to IT infrastructure. From industry trends and best practices to tips and tricks for managing complex systems, my goal is to provide valuable information that will help IT professionals and enthusiasts alike. Whether you are a seasoned IT veteran or just getting started in the field, I hope you will find my blog to be a valuable resource. In addition to sharing my own thoughts and ideas, I also welcome feedback, comments, and questions from my readers. I believe that a collaborative approach is the best way to advance the field of IT infrastructure and I look forward to hearing from you. Thank you for visiting my blog, and I hope you will continue to follow along as I explore the fascinating world of IT infrastructure. Sincerely, Amit Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *