Skip to main content

Group Policy and PowerShell

You can manage Group Policy via PowerShell... who knew!? 🤣

 

Listing GPOs

Get-GPO -All | Sort-Object -Property DisplayName | FT -Property DisplayName,Owner,GpoStatus,Description
Get-GPO -All -Domain domain.loc -Server dc1.domain.loc | Sort-Object -Property DisplayName | FT -Property DisplayName,Owner,GpoStatus,Description

 

Generating GPO reports

# Generate a GPO Report for a single named GPO
$gpoName = "PowerShell Logging"
Get-GPO -All | Where-Object { $_.DisplayName -eq $gpoName } | ForEach-Object {
  $reportPath = "C:\GPOReports\" + $_.DisplayName + ".html"
  Get-GPOReport -GUID $_.ID -ReportType HTML -Path "$($reportPath)"
}
# Generate GPO reports for all GPOs
Get-GPO -All | Sort-Object -Property DisplayName | ForEach-Object {
  $reportPath = "C:\GPOReports\" + $_.DomainName + " - " + $_.DisplayName + ".html"
  "Generating report for $($_.DisplayName) in $($reportPath)..."
  Get-GPOReport -GUID $_.ID -ReportType HTML -Path "$($reportPath)"
}