Skip to main content
Jorge Bernhardt Jorge Bernhardt
  1. Posts/

Using PowerShell to Create BPA Reports in HTML Format

·333 words·2 mins· 100 views · 5 likes ·
Get-BPAModel Get-BPAResult Invoke-BPAModel Microsoft

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

Next, we define which BPA model will be executed, in this case, I will use the Microsoft DNS server. Then we start a scan with Invoke-BPAModel cmdlet.

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

Once we have the scan findings, we can use PowerShell to create HTML reports with the results. To do this, we first define the variables with the characteristics of the HTML report.

$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}

$body = "<H1>BPA Report</H1><h2></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

As you can see in the parameters of the command, I have selected only the results with severity level “Error” or “Warning”, but if you want, you can include the level “Information”
BPA PowerShell

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.