PowerShell - Using the Windows Server Best Practice Analyzer
3 min read · Updated 29 February 2024
Hello,
The Best Practices Analyzer (BPA) is a tool built into Windows Server that checks whether certain configurations (mainly roles) comply with best practices.
It can be interesting to check, for the best practices available, whether you comply with them.
These best practices do not have to be respected; it is up to you to judge if, in your context, they seem relevant to you.
In this article, I show you how to use the Windows Server Best Practice Analyzer in PowerShell.
# List available BPA.Get-BPAModel | Select-Object -Property Name,Id, LastScanTime# But a few more are listed as followsGet-WindowsFeature | Where-Object {$_.BestPracticesModelId -ne ''} | Select-Object -Property name,BestPracticesModelId
# Run an analysis using the ID# If the role/functionality is not installed on the server, you will get an errorInvoke-BpaModel -ModelID 'Microsoft/Windows/DirectoryServices
# Run an analysis of all the BPAs for which the role is installed on the workstationGet-WindowsFeature | Where-Object {($_.BestPracticesModelId -ne '') -and ($_.'InstallState' -eq 'installed')} | Invoke-BpaModel
# Display the result of the analysisGet-BpaResult -ModelID Microsoft/Windows/DirectoryServices | Where-Object Resolution -ne $null | Select-Object -Property severity, Problem, Resolution,help
# Display results classified as errors or warningsGet-BpaResult -ModelId 'Microsoft/Windows/DirectoryServices' | Where-Object { $_.severity -match 'warning|error' }
# Display the result of the analysis in an interactive tableGet-BpaResult -ModelID Microsoft/Windows/DirectoryServices | Where-Object Resolution -ne $null | Out-GridView
# Export results as CSVGet-BpaResult -ModelID Microsoft/Windows/DirectoryServices | Where-Object Resolution -ne $null | Export-Csv -path c:\bpa_results.csv
# Export results in htmlGet-BpaResult -ModelID Microsoft/Windows/DirectoryServices | Where-Object Resolution -ne $null | ConvertTo-Html > c:\bpa_results.html
# Exclude results# Exclusion will only make elements invisible in the graphical interface (in the server manager).# You need to filter the rules you wish to excludeGet-BPAResult -ModelID Microsoft/Windows/DirectoryServices | Where-Object { $_.RuleID -eq 44} |Set-BPAResult -Exclude $true# Another exampleGet-BPAResult -ModelID Microsoft/Windows/DirectoryServices | Where-Object { $_.Severity -eq "Information"} | Set-BPAResult -Exclude $true
# Remove the exclusionGet-BPAResult -ModelID Microsoft/Windows/DirectoryServices | Where-Object { $_.RuleID -eq 44} | Set-BPAResult -Exclude $false# Another exampleGet-BPAResult -ModelID Microsoft/Windows/DirectoryServices | Where-Object { $_.Severity -eq "Information"} | Set-BPAResult -Exclude $falseRelated links
- PowerShell
PowerShell - Simply send objects to different variables
PowerShell - Tip - Simply send objects to different variables
1 min read
- PowerShell
Test-Connection and Test-NetConnection
Ping with Test-Connection (ping count, boolean result, remote pings over WinRM) and check SMB, HTTP or RDP ports with Test-NetConnection.
2 min read
- PowerShell
PowerShell - Display network connections (equivalent to netstat)
Display network connections (listening ports, active connections...)
2 min read
- PowerShell
PowerShell - Testing name resolution (equivalent to nslookup)
PowerShell commands to test name resolution (equivalent to nslookup)
2 min read
- PowerShell
PowerShell - View and manage DNS configuration of network interfaces
PowerShell commands to display and manage DNS configuration of network interfaces
4 min read
- PowerShell
PowerShell - Managing IP configuration of network interfaces
PowerShell commands to view and modify the IP configuration of network interfaces
4 min read
New site · Reference
The Windows directory tree
Native Windows folders, files and logs: what they are for, what they contain, with commands and Microsoft sources.
Browse the treeNew site · Reference
Group Policy settings
ADMX settings for Windows 10, 11, Server and applications: registry keys, PowerShell commands and use cases.
Browse the policies