This PowerShell script shows how to get Best Practice Analyzer result.
Best Practices Analyzer (BPA) is a server management tool that is available in Windows Server 2012. BPA can help administrators reduce best practice violations by scanning roles that are installed on managed servers that are running Windows Server 2012. This script is based on BPA PowerShell model to get specific BPA model result.
Step1: To run Windows PowerShell as an administrator from the
Start screen, right-click the Windows PowerShell tile in the
Apps results; then on the app bar, click Run as administrator. Then, type the command< Script Path> at the Windows PowerShell Console.

Step 2: You can type the command Get-Help Get-OSCBpaResult –Full
to display the entire help file for this function, such as the syntax, parameters, or examples.

Here are some code snippets for your reference.
$ModelID = (Show-OSCBpaModel | Where ID -EQ $ID).ModelID
Try
{
Get-BpaResult -ModelId $ModelID -ErrorAction Stop | Select-Object -Property "ResultNumber","ResultID",`
"ComputerName","Title","Severity","Category",@{Expression={If($_.Problem -eq $null){"Null"}};Label="Problem"},`
@{Expression={If($_.Impact -eq $null){"Null"}};Label="Impact"},`
@{Expression={If($_.Resolution -eq $null){"Null"}};Label="Resolution"}`
| ConvertTo-Html | Set-Content -Path "$ExportTo\BpaReport_$key.html"
Write-Host "Successfully generated Bpa result in $ExportTo\BpaReport_$key.html"
}
Catch
{
Write-Warning "There has been a Best Practice Analyzer error for Model Id '$ModelID'. The Result file has not yet been generated. Please perform the scan first and try again."
}
$ModelID = (Show-OSCBpaModel | Where ID -EQ $ID).ModelID Try { Get-BpaResult -ModelId $ModelID -ErrorAction Stop | Select-Object -Property "ResultNumber","ResultID",` "ComputerName","Title","Severity","Category",@{Expression={If($_.Problem -eq $null){"Null"}};Label="Problem"},` @{Expression={If($_.Impact -eq $null){"Null"}};Label="Impact"},` @{Expression={If($_.Resolution -eq $null){"Null"}};Label="Resolution"}` | ConvertTo-Html | Set-Content -Path "$ExportTo\BpaReport_$key.html" Write-Host "Successfully generated Bpa result in $ExportTo\BpaReport_$key.html"} Catch { Write-Warning "There has been a Best Practice Analyzer error for Model Id '$ModelID'. The Result file has not yet been generated. Please perform the scan first and try again."}
Example 1: How to get BPA result in Windows Server 2012
First, we need to type Show-OSCBpaModel command to obtain current virtual machine information in the Windows PowerShell Console.

After that, type Get-OSCBpaResult -ID 14 -ExportTo C:\Script command shows how to get the Bpa result and generate a report to the D:\Script folder.
![]()
The report generated is as shown below.

Windows PowerShell 3.0
Windows Server 2012