Using PowerShell to Create BPA Reports in HTML Format
In this post, I want to show you how to use PowerShell to create HTML reports with the Best Practices Analyzer (BPA) results.
Best Practices Analyzer (BPA) is a server management tool that is available in Windows Server. This tool helps administrators apply the best practices by scanning one or more roles that are installed on our server. BPA can be used locally or remotely using the Server Administrator GUI or using the Windows PowerShell cmdlets.
Follow the steps below to generate an HTML report that retrieves information from the BPA results. First, use the Get-BPAModel PowerShell cmdlet to retrieve the list of compatible models with the Best Practices Analyzer (BPA) installed on your server. Use the cmdlet with the following syntax:
Get-BpaModel `
| Select-Object id, Name, LastScanTIme | ft

$BPA = "Microsoft/Windows/DNSServer"
Invoke-BpaModel -ModelId $BPA

$head = '<Style>
BODY {font-size:0.9em; font-family:Lucida Console;background-color:#A4A4A4;}
TABLE{font-size:0.8em; border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {font-size:1.2em; border-width: 1px;padding: 2px;border-style:solid;border-color: black; background-color: #9A2EFE}
TD {border-width: 1px;padding: 2px;border-style:solid;border-color: black; background-color: #58ACFA}
</style>'
$body = "<H1>BPA Report</H1><h2>www.JorgeBernhardt.com</h2>"
$title = "BPA Report"
and finally, we use the Get-BpaResult cmdlet with the following syntax.
Get-BpaResult `
-ModelId $BPA `
| where-Object {$_.Severity -eq "Error" -or $_.Severity -eq "Warning"} `
| Sort-Object -Property Severity `
| ConvertTo-Html -Head $head -Body $body -Title $title `
| Out-File d:\report.html


Thanks for reading my post. I hope you find it helpful.
If you want to know more about Best Practices Analyzer, check out this link.