Using the Hyper-V best practices analyzer

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.

Getting ready

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.

Note

Best Practices Analyzer is not supported in Nano Server. BPA is completely Cmdlets based and written in C# back during the days of PowerShell 2.0. It is also statically using some .NET XML library code that was not part of .NET framework at that time.

How to do it...

By following these steps, you will see how to run the BPA for Hyper-V and explore its results:

  1. Open the Server Manager from the Windows Taskbar.
  2. From the Server Manager window, click on Hyper-V on the pane on the left-hand side. Then use the scroll bar on the right-hand side to scroll down until the Best Practices Analyzer option can be seen.
  3. Under Best Practices Analyzer, navigate to Tasks | Start BPA Scan, as shown in the following screenshot:
    How to do it...
  4. In the Select Servers window, select the Hyper-V servers that you want to scan and click on Start Scan.
  5. The scan will start on all the selected servers. When the scan has finished, the BPA results will be shown in Server Manager, under Best Practices Analyzer.
  6. When completed, the scan results will be listed in three columns: Server Name, Severity, and Title. Use the filters above each column to organize the information based on your queries.
  7. Click on one of the results to see the information provided by BPA. The following screenshot shows an example of an error scan result and its description:
    How to do it...
  8. Open the results and analyze the problem, impact, and resolution for each server.
  9. Use the filter at the top to find only warnings and errors.
  10. After identifying the results, you can apply the resolutions provided by the Hyper-V BPA.

How it works...

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.

There's more...

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:

There's more...

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:

There's more...

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.

Using PowerShell to create HTML reports with the BPA results

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:

Using PowerShell to create HTML reports with the BPA results
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.247.196