Microsoft has created a few rules to help you improve your environments—these are referred to as best practices. However, it is not easy to know all of them and to make sure your Hyper-V servers are compliant with all of these practices.
To make this job easier, Windows Server comes with the Best Practices Analyzer (BPA). It has a set of best practices and rules which it will compare against all the components of your server, and it will then generate a report with all the problems that are found during the scan. The report will provide helpful details, such as problems, impact, and resolutions for possible issues.
Windows Server comes with best practices for almost all the roles, as well as a specific one only for Hyper-V, with all the practices to analyze your host server, configuration, and VMs.
This recipe will show you how to use the Hyper-V Best Practices Analyzer to analyze your systems.
The Hyper-V Best Practices Analyzer works only with the pre-installed Hyper-V Role; this includes Windows Server 2016 Hyper-V in Full, Server Core, and the free Hyper-V Server. Make sure that Hyper-V is installed and, as a best practice, run the BPA after every server installation and configuration is performed.
By following these steps, you will see how to run the BPA for Hyper-V and explore its results:
The BPA for Hyper-V has 66 scans to identify which settings are not configured, based on the Microsoft documentation and practices. It is enabled automatically when the Hyper-V role is installed.
When BPA scans the servers, it shows the results for every scan, providing helpful details about what was scanned, the impact, and even how to resolve any problems it finds. It will also give you the option to apply the necessary changes for your server in compliance with the best practices.
BPA is available through Server Manager and can be used at any time. The recommendation is to scan every server after final configuration, and on a monthly basis after that.
Hyper-V BPA will also display information about Microsoft Support. If the server has a configuration that is not supported by Microsoft, it will inform you of this through the reports.
After running and applying the recommended settings, you can then be sure that your servers have all the best practices currently recommended by Microsoft.
It is also recommended that Hyper-V servers in the production environment are scanned using the Hyper-V BPA every month to ensure the Hyper-V environment is healthy.
All Windows best practices are also available through PowerShell. You can scan, filter, get the results, and extract reports using the PowerShell cmdlets.
To start a scan using the Hyper-V BPA, type the following command:
Invoke-BpaModel –BestPracticesModelId Microsoft/Windows/Hyper-V
After invoking the Hyper-V BPA, you can use the Get-BPAResult
command to analyze the results. The following command shows the BPA scan results:
Get-BpaResult –BestPracticesModelId Microsoft/Windows/Hyper-V
The following screenshot is an example of how the Get-BPAResult
output might look:
If you want to filter only the warnings and errors by using PowerShell, you can also use the following command:
Get-BpaResult -BestPracticesModelId Microsoft/Windows/Hyper-V | Where-Object {$_.Severity –eq "Warning" –or $_.Severity –eq "Error"}
You can also configure PowerShell to only display some of the more useful information about each error, using the following command:
Get-BpaResult –ModelId Microsoft/Windows/Hyper-V | Where-Object {$_.Severity –eq 'Error'} | FL Title, Problem, Resolution, Help
Here is the result:
As you can see in the preceding screenshot, this command's output is much more helpful than what was originally displayed using Get-BpaResult
alone.
To improve the PowerShell results, it is possible to produce a BPA HTML report using the following command. This script uses the previous Get-BpaResult
filter example to show only the warning and error results:
$head = '<style> BODY{font-family:Verdana; background-color:lightblue;} TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;} TH{font-size:1.3em; border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:#FFCCCC} TD{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:yellow} </style>' $header = "<H1>Hyper-V BPA Errors and Warnings Results</H1>" $title = "Hyper-V BPA" Get-BpaResult -BestPracticesModelId Microsoft/Windows/Hyper-V | Where-Object {$_.Severity -eq "Error" -or $_.Severity -eq "Warning" } | ConvertTo-HTML -head $head -body $header -title $title | Out-File report.htm . eport.htm
The following screenshot shows the output file that is created after running the script:
3.129.247.196