Hyper-V BPA Automation with Powershell

Russian Version

Intro

I have a lot of tasks related with the collecting of information about the virtual infrastructure. One of the steps of any audit is to get and analyze configuration compliance best practices. This stage always includes a manual check and BPA Analyzer for Hyper-V. BPA Analyzer became available in 2008 R2 (as a separate KB http://support.microsoft.com/kb/977238/en-us). But starting with Server 2012/2012 R2, BPA Hyper-V is already included in the RTM- version and can be run from the ” box “, using the Server Manager or module BestPractices. BPA Analyzer scans the Hyper-V role , including host configuration and virtual machines , and displays warnings about infractions of the best practices within the console and in the Server Manager. Obviously, If we have a large number of Hyper-V hosts, we need to automate this process. And,yes, automation=powershelling Улыбка. Script is very simple. Tested on 2008 R2/2012.

TIP: This is not the last revision of this script. I will update post and script if I add some fixies or features. Please, follow me to receive any updates and feel free to write comments.

TIP: To succesfully run the script you shoud verify that ExecutionPolicy is RemoteSigned (Set-ExecutionPolicy -RemoteSigned) and PsRemoting is enabled on remote servers (Enable-PsRemoting).Usually, it’s not necessary.

TIP: download link at the end of the post

Script performs..

1. Creates a folder C: \ BPA and C: \ BPA \ reports for storing reports and source data. If the folder Reports already exists , the process of creation is skipped.

2. Prompts you to enter a name NETBIOS-Hyper-V servers and stores the entered names in the file hvhosts.csv  with the correct format

3. For each NETBIOS-name checks for installed Hyper-V role and starts scanning the BPA

4. Converts results (only warnings or errors) to the HTML-file (bpa/reports/bpa_servername.html) and automatically opens each report in browser

#Check the availability of the necessary files and folders
$test=Test-Path c:\BPA\Reports
If ($test -eq $false)
{ #Creating folders and files if we don't have them
New-Item c:\BPA -ItemType Directory
New-Item c:\BPA\Reports -ItemType directory
New-Item C:\BPA\hvhosts.csv -ItemType file
Add-Content -Path C:\BPA\hvhosts.csv -Value "HyperVhost"
Write-Host "Folders/Files were created. Now you MUST define Hyper-V Server Names" -ForegroundColor Red -BackgroundColor white
}
Else {Write-Host "There is nothing to create. Jump To The Next Step" -ForegroundColor Red -BackgroundColor white}
#HVhosts will keep our netbios names
$csvfile="C:\BPA\hvhosts.csv"
#Fill hvhosts from console(!). type server names separated by commas
[string]$name=Read-Host "Enter Hyper-V NETBIOS Name (separated by commas)"
$name.Split(",")|% {$_.trim()}|Add-Content C:\BPA\hvhosts.csv
#Import file HVHOSTS with Hyper-V host names
Import-csv $csvfile|foreach {
#Variable $hv keeps our netbios names
$hv=$_.HyperVhost;
$grole=Get-WindowsFeature Hyper-V
#Check if servers has really Hyper-V role installed
ICM -ScriptBlock {
If ($grole.Installed -eq $False) {write-host "You don't have hyper-v on $hv" -ForegroundColor Red -BackgroundColor Blue}
else {write-host "Server $hv has hyper-v installed feauture. Everything is OK. Doing a BPA Scan. HTML will open automatically" -ForegroundColor red -BackgroundColor White}}
#Show BPA collecting status
Write-host "Collecting BPA Information on $hv" -foreground Yellow;
#Run BPA tasks on servers
ICM -ScriptBlock {
 #Import all necessary modules (for PS 3.0 it's now neccessary, but PS 2.0 requires this step)
 Import-Module ServerManager
 Import-Module BestPractices
 #Start BPA Scan
 Invoke-BPAModel -BestPracticesModelID Microsoft/Windows/Hyper-V
 #HTML Style
 $head = "<style>"
 $head = $head + "BODY{background-color:white;}"
 $head = $head + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
 $head = $head + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
 $head = $head + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
 $head = $head + "</style>"
 #Take BPA Results(only warning and errors. if you have non-English OS you SHOULD change "error" and "warning" )
 Get-BpaResult -BestPracticesModelId Microsoft/Windows/Hyper-V |
 Where-Object {$_.Severity -eq "Error" -or $_.Severity -eq “Warning” }|
 #Convert BPA report to HTML
 ConvertTo-Html -Property Severity,Category,Title,Problem,Impact,Resolution,Help -body "<H2>Hyper-V BPA Report</H2>" -head $head
} |
 #Create HTML-report named as bpa_nameofserver.html
 Out-File "C:\BPA\reports\bpa_$hv.html"
#Open HTML
 Invoke-Expression "C:\BPA\reports\bpa_$hv.html"
}

#Created by Roman Levchenko. 2014.www.rlevchenko.com
#Please do not remove copyrights

Process

hv_bpa_1

Folder “Reports”

hv_bpa_2

Report

hv_bpa_3

DOWNLOAD LINK

Study Guide 74-409

What is the exam 74-409?

74-409 is the new exam from Microsoft that replaces 70-659: Server 2008 R2, Server Virtualization .When you pass the exam 74-409 you complete the requirements for the Microsoft Certified Specialist: Server Virtualization with Hyper-V and System Center.

There are 45 questions and two sections in the exam. Test questions are almost 80% , drag-and-drop is 20%. In the drag-and-drop section you have to provide a real solution for corporate task.

For example, Contoso have 2 Hyper-V hosts with Server 2012 R2 installed. IT department plans to implement Virtual Fibre Channel into VM1. Which four actions should you do to complete this task? Then you must choose answers, using drag-and-drop, in the correct order.  Additional information you can get here

What should I know to successfully pass exam?

Before you start your preparation for exam, it’s very important to understand what’s new in the R2 versions

What’s new in Hyper-V Server 2012 R2

What’s new in Failover Clustering in Server 2012 R2

What’s new in VMM 2012 R2

What’s new in DPM 2012 R2

What’s new in SCOM 2012 R2

Then you have to review all article, provided below. Try to remember all requirements for features and how they are deploying, including Powershell methods.

Configure Hyper-V (35-40%)

  • Create and configure virtual machine settings

Dynamic Memory: http://technet.microsoft.com/ru-ru/library/hh831766.aspx; http://www.aidanfinn.com/?p=12237

Resource Metering:http://technet.microsoft.com/ru-ru/library/hh831661.aspx

Hyper-V Integration Services: http://www.virtualizationadmin.com/articles-tutorials/microsoft-hyper-v-articles/performance-tuning/windows-server-2012-hyper-v-integration-services.html

Guest Integration Services (new “guest service” in 2012 R2):http://blogs.technet.com/b/keithmayer/archive/2013/11/22/why-r2-guest-services-in-windows-server-2012-r2-hyper-v.aspx#.Uzq7Tvl_ufI

Smart Paging: http://windowsitpro.com/hyper-v/q-i-notice-windows-server-2012-virtual-machines-have-smart-paging-file-location-what-smart-p

VM Generations: http://blogs.technet.com/b/jhoward/archive/2013/10/24/hyper-v-generation-2-virtual-machines-part-1.aspx

Extended session mode: http://technet.microsoft.com/en-us/library/dn282274.aspx

  • Create and configure virtual machine storage

Operations:http://blogs.technet.com/b/yungchou/archive/2013/01/23/hyper-v-virtual-hard-disk-vhd-operations-explained.aspx

Online resizing VHDX: http://technet.microsoft.com/en-us/library/dn282286.aspx

Snapshots: snapshots are now “checkpoints” and if you are using 2012/R2 you CAN delete snapshot while VM is running. Merge process will start at the background. You now don’t have to shutdown VM! Powershell cmdlet is Checkpoint-VM

Diff Disks: http://blogs.technet.com/b/canitpro/archive/2013/05/29/step-by-step-creating-differencing-disks.aspx

Path-through disks: http://windowsitpro.com/hyper-v/features-lost-using-hyper-v-2012-passthrough-storage

Virtual Fibre Channel: http://technet.microsoft.com/en-us/library/dn551169.aspx
Storage QoS: http://technet.microsoft.com/en-us/library/dn282281.aspx

  • Create and configure virtual networks

Virtual Switches: http://www.serverwatch.com/server-tutorials/harnessing-the-power-of-hyper-v-network-virtual-switches.html

Network QoS: http://www.petri.co.il/configure-qos-quality-of-service-rules-windows-server-2012.htm NOTE: you cannot use QoS for incoming traffic! Only for outbound!

Nic Teaming: main diff between 2012 and R2 is Microsoft has added new balancing method called “Dynamic”. For hyper-v it’s recommended  using Switch Independent + Dynamic. See more info here

Network Isolation: VLAN and PVLANs http://technet.microsoft.com/en-us/library/jj679878.aspx#bkmk_pvlan

Configure and Manage Virtual Machine High Availability (15-20%)

  • Configure failover clustering with Hyper-V

Cluster Shared Volumes: http://technet.microsoft.com/en-us/library/jj612868.aspx

Quorum: http://technet.microsoft.com/en-us/library/jj612870.aspx

Cluster Networking: http://technet.microsoft.com/en-us/library/dn550728.aspx

СAU Updating: http://technet.microsoft.com/en-us/library/hh831694.aspx

Active Directory-Detached Cluster:  http://technet.microsoft.com/en-us/library/dn265970.aspx

Deploy Hyper-V Cluster: http://technet.microsoft.com/en-us/library/jj863389.aspx

  • Manage failover clustering roles

Guest-Clustering: http://technet.microsoft.com/en-us/library/dn265980.aspx

Scale-Out/File Shares: http://blogs.technet.com/b/canitpro/archive/2013/12/11/scale-out-file-shares-and-continuously-available-file-services.aspx

VM Monitoring: http://blogs.msdn.com/b/clustering/archive/2012/04/18/10295158.aspx

Cluster settings: I would recommend to review cmdlets Get-Cluster|fl * and Get-ClusterGroup –Name “cluster name”|fl *

  • Manage virtual machine movement

Live Migration: http://technet.microsoft.com/ru-ru/library/hh831435.aspx

Quick Migration:  main diff between live migration and quick migration – saved state. Quick migration performs save VM and then move it to another host with a little downtime. During process ‘Save VM” hyper-v is saving memory to shared disk (if cluster) , unattaching vm from host and re-attaching vm to another host.

Export VM: http://technet.microsoft.com/en-us/library/dn282278.aspx#bkmk_export

Import VM: http://blogs.technet.com/b/heyscriptingguy/archive/2013/10/17/powertip-import-a-hyper-v-virtual-machine-with-only-its-xml-file.aspx

Network health protection: http://technet.microsoft.com/en-us/library/dn265972.aspx#BKMK_VMHealth

Drain on shutdown: http://technet.microsoft.com/en-us/library/dn265972.aspx#BKMK_VMDrain

P2V: http://technet.microsoft.com/en-us/library/hh427286.aspx + http://technet.microsoft.com/en-us/library/hh427293.aspx (very important!)

V2V: http://technet.microsoft.com/ru-ru/library/gg610672.aspx

VMs to Cloud: http://blogs.technet.com/b/cbernier/archive/2014/01/27/move-vm-s-between-hyper-v-and-windows-azure.aspx

Implement a Server Virtualization Infrastructure (35-40%)

  • Implement virtualization hosts

Host Resource optimization: http://technet.microsoft.com/en-us/library/gg675109.aspx

VMM Library: http://technet.microsoft.com/en-us/library/gg610598.aspx

Add hosts to VMM: http://technet.microsoft.com/en-us/library/gg610671.aspx

Self-service : http://technet.microsoft.com/en-us/library/gg610573.aspx

Integrate third-party virtualization: http://technet.microsoft.com/en-us/library/gg610687.aspx

Bare Metal : http://technet.microsoft.com/en-us/library/gg610634.aspx

  • Implement virtual machines

Adding VM to VMM: http://technet.microsoft.com/en-us/library/hh368991.aspx

Placement rules: http://technet.microsoft.com/en-us/library/hh368991.aspx

VM templates: http://technet.microsoft.com/en-us/library/hh368987.aspx

Shared VHDX: http://technet.microsoft.com/en-us/library/hh368987.aspx

Placement rules (cluster): http://blogs.technet.com/b/scvmm/archive/2013/03/11/custom-placement-rules-and-availability-sets-in-scvmm-2012-sp1.aspx

  • Implement virtualization networking

VMM Logical Networks: http://blogs.technet.com/b/scvmm/archive/2013/02/14/networking-in-vmm-2012-sp1-logical-networks-part-i.aspx; http://technet.microsoft.com/en-us/library/gg610596.aspx

Networking in VMM: POSTER

Windows Server Gateway: http://technet.microsoft.com/en-us/library/dn313101.aspx

Network isolation VMM: http://blogs.technet.com/b/scvmm/archive/2013/06/04/logical-networks-part-iv-pvlan-isolation.aspx ; http://blogs.technet.com/b/scvmm/archive/2013/05/22/logical-networks-part-iii-network-isolation.aspx

Network virtualization: http://blogs.technet.com/b/privatecloud/archive/2013/01/23/network-virtualization-guide-with-system-center-2012-virtual-machine-manager-service-pack-1-by-kristian-nese.aspx

Converged networks: http://www.thomasmaurer.ch/2013/04/hyper-v-converged-fabric-with-system-center-2012-sp1-virtual-machine-manager/

  • Implement virtualization storage

CSV: http://technet.microsoft.com/en-us/library/gg610692.aspx

vFC VMM: http://technet.microsoft.com/en-us/library/dn458365.aspx

Online resizing: http://blogs.msdn.com/b/virtual_pc_guy/archive/2014/01/29/online-vhdx-resize-with-scvmm-2012-r2.aspx

SMB: http://blogs.technet.com/b/trentsh/archive/2012/09/07/how-to-register-smb-3-0-shares-in-scvmm-2012-sp1-beta.aspx

  • Manage and maintain a server virtualization infrastructure

Dynamic Optimization: http://technet.microsoft.com/en-us/library/gg675109.aspx

SCOM Integration: http://technet.microsoft.com/en-us/library/hh427287.aspx

SCSM<>VMM: http://technet.microsoft.com/sl-si/video/integrating-scsm-and-vmm-demo.aspx

DPM: http://technet.microsoft.com/en-us/library/hh757970.aspx

Monitor and Maintain a Server Virtualization Infrastructure (15-20%)

  • Plan and implement a monitoring strategy

ACS: http://technet.microsoft.com/en-us/library/hh298613.aspx

Global Service Monitor: http://technet.microsoft.com/en-us/library/jj860368.aspx

AD Monitoring: http://www.microsoft.com/en-us/download/details.aspx?id=21357 (refer MP Guide)

APP Monitoring: http://www.microsoftvirtualacademy.com/training-courses/app-performance-monitoring-with-system-center-2012-r2

  • Plan and implement a business continuity and disaster recovery solution

Clone AD: http://blogs.technet.com/b/aman/archive/2013/01/17/cloning-virtual-domain-controller-in-server-2012-active-directory-2012.aspx

Hyper-V Replica: http://technet.microsoft.com/en-us/library/jj134172.aspx

Recycle Bin: http://technet.microsoft.com/en-us/library/hh831702.aspx

DPM Planning: http://technet.microsoft.com/en-us/library/hh758140.aspx

WBADMIN: http://technet.microsoft.com/en-us/library/cc753528.aspx

AD Backup: http://technet.microsoft.com/library/cc771290(WS.10).aspx

——–

UPDATE (21.06.2014): I found an interesting guide in PDF format from Veeam and Orin Thomas. Download here

TIP: specific course for this exam is available on MVA (subtitles are included!)

TIP: Voucher for 50% off (updated 02/10/15: no vouchers for now. but second shot is back!)

TIP: Exam Voucher (updated 03/04: vouchers are no longer available but you can get 15% off ~not available)

TIP: To practice you can use virtual labs 

I hope you enjoy this post. Wish you get luck on the exam!