Public/Export-GPOComments.ps1
#requires -Modules GroupPolicy function Export-GPOComments { <# .SYNOPSIS Compile HTML Report of GPO comments .DESCRIPTION Compile an HTML report of comments embedded within GPOs, GPO Settings and GP Preferences settings .PARAMETER GPOName Name(s) of Group Policy Objects or '*' for all GPOs .PARAMETER ReportFile Path and name of new HTML report file .PARAMETER StyleSheet Path and name of CSS template file .EXAMPLE Export-GPOComments -GPOName '*' -ReportFile ".\gpo.htm" .EXAMPLE $GpoNames | Export-GPOComments -ReportFile ".\gpo.htm" .EXAMPLE Export-GPOComments -ReportFile ".\gpo.htm" -StyleSheet ".\mystyles.css" .NOTES 1.1.0 - 11/14/2017 - David Stein #> param ( [parameter(Mandatory = $True, ValueFromPipeline = $True, HelpMessage = 'Name of Policy or Policies')] [ValidateNotNullOrEmpty()] [string[]] $GPOName, [parameter(Mandatory = $True, HelpMessage = 'Path to report file')] [ValidateNotNullOrEmpty()] [string] $ReportFile, [parameter(Mandatory = $False, HelpMessage = 'Path to custom CSS file')] [string] $StyleSheet = "" ) if ($GPOName -eq '*') { Write-Verbose "loading all policy objects: preferences" $gpos = Get-GPO -All | Sort-Object -Property DisplayName } else { Write-Verbose "loading specific policy objects" $gpos = $GPOName | Foreach-Object {Get-GPO -Name $_} } if ($StyleSheet -eq "") { $ModulePath = $((Get-Module GPODoc).Path -replace ('GPODoc.psm1', '')) $StyleSheet = "$ModulePath\assets\default.css" } if (!(Test-Path $StyleSheet)) { Write-Warning "Error: Stylesheet file not found: $StyleSheet" break } $ReportTitle = "Group Policy Comments - $GPOName" $fragments = @() $fragments += "<h1>Group Policy Report</h1>" foreach ($gpo in $gpos) { $gpoName = $gpo.DisplayName Write-Output "GPO: $gpoName" $desc = Get-GpoComment -GPOName $gpoName -PolicyGroup Policy $sett = Get-GpoComment -GPOName $gpoName -PolicyGroup Settings $pref = Get-GpoComment -GPOName $gpoName -PolicyGroup Preferences Write-Verbose $desc $fragments += "<h2>$gpoName</h2>" $fragments += $desc | ConvertTo-Html -As List $fragments += "<h3>Policy Settings</h3>" $fragments += $sett | ConvertTo-Html -Fragment $fragments += "<h3>Preferences</h3>" $fragments += $pref | ConvertTo-Html -Fragment } $fragments += "<p class='footer'>Generated by GPODoc - http://github.com/skatterbrainz/GPODoc - $(Get-Date)</p>" ConvertTo-Html -Body $fragments -CssUri $StyleSheet -Title $ReportTitle | Out-File $ReportFile -Force } Export-ModuleMember -Function Export-GPOComments |