Windows Server 2012 Hyper-V: Configure VM Processor Compatibility via PowerShell

Windows Server 2012 Logo

If you have a mixed Hyper-V environment with Hyper-V hosts which have different CPU generations you may cannot live migration Virtual Machines from one Hyper-V host to another without setting the VM CPU Compatibility setting.

Note: I saw a lot of different environments where different generation of Intel CPUs were used, and most of the time Live Migration did still work. I would recommend to set this setting only if you really need it.

Hyper-V VM Processor Compatibility

If you need to do this for multiple Virtual Machines you may better use Windows PowerShell to do this.

To do this you can use the new Hyper-V PowerShell module and the Get-VMProcessor and Set-VMProcessor cmdlet. With the Get-VMProcessor cmdlet you can get information about the virtual CPU of VMs. You can list this for all virtual machines running on one host by using the following command


Get-VMProcessor *

Hyper-V Get-VMProcessor

To change this setting for all virtual machines running on the Hyper-V host you can use the following PowerShell command. This does only working with virtual machines which are not running.


Get-VMProcessor * | Set-VMProcessor -CompatibilityForMigrationEnabled 1

Hyper-V Set-VMProcessor

If you want to shut down all the VMs first you can use the following command.


Get-VM | Stop-VM

If you just want to do this for a single VM you can use the following commands.


Get-VM TMG | Stop-VM

Get-VM TMG | Set-VMProcessor -CompatibilityForMigrationEnabled 1

Hyper-V Set-VMProcessor Single VM

To do a full automation you could do it the following way:


Get-VM * | Stop-VM

Get-VM * | Set-VMProcessor -CompatibilityForMigrationEnabled 1

Get-VM * | Start-VM

As you can see you can also find the “CompatibilityForOlderOperatingSystemsEnabled” property to enable Processor Compatibility for legacy Operating Systems in Windows Server 2012 Hyper-V for example Windows NT 4.0 Server or Windows 2000.

Basic Hyper-V Networking in System Center 2012 SP1 – Virtual Machine Manager

System Center Logo

This blog post is a part of a series of blog posts about System Center 2012 Virtual Machine Manager, I am writing together with Michel Luescher (Consultant from Microsoft Switzerland).

In January Microsoft released the Service Pack 1 for System Center 2012. This was more close to a full featured release rather than just a normal maintenance Service Pack with just small changes and bug fixes. The main purpose of System Center 2012 Service Pack 1 is to support Windows Server 2012. But in the special case of Virtual Machine Manager there are also a lot of new features and improvements. One of the biggest investments Microsoft made with SP1 was the Network Management.

Besides the integration of Network Virtualization which came with Windows Server 2012 Hyper-V a new concept call “Logical Switch” has been introduced. These Logical Switches allow you to configure the Virtual Switch and other network components of Hyper-V hosts directly and centralized from Virtual Machine Manager.

Network Definitions

Logical Networks – Logical Networks represents basically the network infrastructure you have already in your environment. For example this can be a subnet for a specific server or even a storage network. In System Center 2012 Virtual Machine Manager without Service Pack 1 you connected a virtual machine to a Logical Network to connect it to the specific subnet. In Service Pack 1 the concept has been extended with  VM Networks.

Virtual Machine Manager Logical Network Overview

Network sites – Network sites are added to an Logical Network to associate VLANs and subnets to host groups, which are representing the different locations. For example the “CorpNET” network on “Site A” has a different VLAN or subnet than “Site B” uses for the same network. When deploying a new virtual machine to the “CorpNET” network, Virtual Machine Manager automatically detects the right subnet and also adds (if required) the VLAN ID to the specific virtual machines network adapter.

Logical Network

IP Pools – IP Pools are just a pool of IP addresses which can be used to automatically let Virtual Machine Manager to assign static IP addresses from the selected subnet (example CorpNET) to a virtual machine or a physical Hyper-V host. An IP Pool includes also the information about Gateway or DNS Serves which are automatically used for the network adapter configuration.

IP Pool

VM Networks – VM Networks are defined by logical networks and virtual machines are now connected to VM Networks. This is done because of the new Network Virtualization feature in Windows Server 2012 Hyper-V. With this technology multiple VM networks can run on a single logical network.

SCVMM 2012 SP1 Networking 01

As already mentioned the Logical Network is mapped to a VM Network. This mapping is done because with the new Hyper-V Network Virtualization feature you can run multiple VM Networks on a single Logical network.

SCVMM 2012 SP1 Networking

Extended Virtual Switch

Logical Switch – The new Logical Switch is the main part of the new concept Microsoft introduced in System Center 2012 SP1 Virtual Machine Manager. A Logical Switch combines the different configuration objects used to create a new Hyper-V Virtual Switch in your environment, as for example Virtual Switch Extensions, Uplink Port Profiles and Virtual Adapter Port Profiles mapped to Port Classifications.

Native Virtual Adapter Port Profile – The Virtual Adapter Port Profiles define Virtual network adapter definitions like QoS settings, security settings like router or DHCP guard and performance settings like SR-IOV, IPsec task offloading or Virtual Machine Queue (VMQ). The Virtual Adapter Port Profile settings are not just for Virtual Machines they are also used for Virtual Network Adapters (vNIC) attached to the Hyper-V Management OS in a Converged Network setup.

Native Uplink Port Profile – The Uplink Port Profile sets the definition for the physical adapter like which logical networks are available on these physical adapters, the configuration of the LBFO and if Network Virtualization is being used.

Port Classifications – Port Classifications are mapping with Virtual Adapter Port Profiles based on the logical switch the virtual machine runs on. If a Virtual Machine is moved to a Hyper-V hosts with a different logical switch, the port classification links in the background which Virtual Adapter Port Profile has to be used

Port Classification

How this works together

The Logical Switch defines a Virtual Switch with Extensions

SCVMM 2012 SP1 Logical Switch

The Logical Switch has Native Uplink Port Profiles which add information about the Teaming Configuration, which Logical Networks and Network Sites are available on the physical network adapters and if Network Virtualization is allowed.

SCVMM 2012 SP1 Logical Switch2

The Logical Switch has also a Native Virtual Adapter Port Profiles which matches with a Port Classification on the Logical Switch and defines the Virtual Network Adapter settings for Virtual Machines or in a Converged Environment for the Hyper-V Management OS.

SCVMM 2012 SP1 Logical Switch3

I hope this post gives you some basic understanding about the new networking features which are added in Service Pack 1 for System Center 2012 Virtual Machine Manager.

You can find the German Version of this blog post on Michel Lueschers (Consultant Microsoft Switzerland) blog.

How to make an existing Hyper-V Virtual Machine Highly Available

Windows Server 2012 Logo

If you have a running Hyper-V Virtual Machine with is not part of a cluster you can make this virtual machine highly available via the Failover Cluster Manager. First of all the Virtual Machine has to be stored on a shared storage. In Windows Server 2008 R2 this means the Virtual Machine and the attached Virtual Disks had to be stored on a Cluster Shared Volume (C:\ClusterStorage\…), with Windows Server 2012 the VM could also be stored on a SMB 3.0 file share.

Windows Server 2008 R2 Make Virtual Machine Highly Available

And there is also a big difference in Windows Server 2008 R2 Hyper-V and in Windows Server 2012 Hyper-V. In Windows Server 2008 R2 the Virtual Machine had to be offline during you add the VM to the Cluster, and in Windows Server 2012 you can do this online.

First open the Failover Cluster Manager and right click on your Cluster Name in the menu select “Configure Role”

Windows Server 2012 Failover Cluster Manager Configure Role

This started the High Availability Wizard. First select the role you want to make high available, in the Hyper-V case this is “Virtual Machine”.

Windows Server 2012 Failover Cluster Manager High Availability Wizard

Now select the Virtual Machine you want to add to the cluster. Note: In Windows Server 2012 the Virtual Machine can be online, in Windows Server 2008 R2 the Virtual Machine had to be offline.

Select Virtual MachineAfter clicking next on the wizard, you the VMs will be added to the Failover Cluster.

Btw. thanks to Philipp Witschi (itnetx), who I now owe a dinner.

 

Windows Server 2012 Hyper-V: VM Resource Metering via PowerShell

Windows Server 2012 Logo

With Windows Server 2012 Hyper-V Microsoft introduced a new feature in Hyper-V called Resource Metering which allows you to measure the usage of a virtual machine. This allows you to track CPU, Memory, Disk and network usage. This is a great feature especially if you need to do charge back or maybe even for trouble shooting.

Last week I had the chance to test and implement this feature for a customer.

First you can check the available PowerShell cmdlets for Hyper-V or for the the commands which include VMResourceMetering.


Get-Command -Module Hyper-V

Get-Command *VMResourceMetering*

Get-Command VMResourceMetering

The resource metering has to be enabled per Virtual Machine. This is great, so even if you move the virtual machine from one Hyper-V host to another you still have the usage data.

To enable the resource metering you can use the following cmdlet. In my case I enable VM Resource Metering for my VM called SQL2012.


Get-VM SQL2012 | Enable-VMResourceMetering

 

Enable-VMResourceMetering

With the cmdlet Measure-VM you can get the statistic for the VM.


Measure-VM -VMName SQL2012

Get-VM SQL2012 | Measure-VM | select *

Measure-VM

To get the network traffic use the properties of the NetworkMeteredTrafficReport.


(Measure-VM -VMName SQL2012).NetworkMeteredTrafficReport

Measure-VM NetworkMeteredTrafficReport

Here is another great thing, if you want to measure Network from or to a specific network you can use VM Network Adapter ACLs to do so. With ACLs you can not just allow or deny network traffic, you can also meter network traffic for a special subnet or IP address.


Add-VMNetworkAdapterAcl -VMName SQL2012 -Action Meter -RemoteIPAddress 10.10.0.0/16 -Direction Outbound

add-vmnetworkadapteracl measure-vm

Of course you can reset the statistics for the VM.


Get-VM SQL2012 | Reset-VMResourceMetering

reset-vmresourcemetering

And to disable resource metering for the VM use:


Get-VM SQL2012 | Disable-VMResourceMetering

 

I think this is one of the great new features of Windows Server 2012 Hyper-V which gets not a lot of attention but is really important.

If you want to know more about Resource Metering in Hyper-V, checkout the blog post from Lalithra Fernando on the TechNet Virtualization Blog.

First Patch Tuesday with Windows Server 2012 Hyper-V Patches – New version of Hyper-V Integration Services

Hyper-V Integration Services Upgrade

Yesterday Microsoft released some patches for Windows Server 2012 and Windows 8. In this wave Microsoft also included some fixes for Hyper-V and also updated the Integration Services to a new version.

Old Hyper-V Integration Services Version: 6.2.9200.16384
New Hyper-V Integration Services Version: 6.2.9200.16433

To check which version is installed in your virtual machine you can use Windows PowerShell: Get Integration Services Version of Windows Server 2012 Hyper-V Virtual Machines.

So if you are running Windows Server 2008 R2 SP1 virtual machines or later don’t forget to update your Hyper-V Integration Services on those virtual machines. If you are running Windows Server 2012 virtual machines you can normally patch those via Windows Update or WSUS to get the latest Hyper-V integration services.

If you run Windows Server 2012 Cluster Aware-Updating you can us the Self-Service update feature to patch your Hyper-V Cluster automatically.

Get Integration Services Version of Windows Server 2012 Hyper-V Virtual Machines

Windows Server 2012 Logo

In System Center 2012 Virtual Machine Manager was a cool new feature which allowed you to show the installed version of the Hyper-V Integration Services. In the normal Hyper-V Manager or Cluster Manager it was not possible to show the installed version. In Windows Server 2012 Hyper-V this has not changed, there is no GUI option to show the installed version, but there is Windows PowerShell. With the simple Get-VM cmdlet you can show the version of the Hyper-V Integration Services.


Get-VM | ft Name, IntegrationServicesVersion

Windows Server 2012 Hyper-V Integration Services PowerShell

Create Multiple Hyper-V Virtual Machines via PowerShell

Windows Server 2012 Logo

For a demo installations I needed a lot of Virtual Machines so I had to choose between creating all the Virtual Machines via Hyper-V Manager which is not really a great option. The best option in this case would be doing this via Windows PowerShell, and with the new Hyper-V PowerShell module in Windows Server 2012 this is very easy and took me only some minutes to get this quick and dirty script. Because this script is only used for my lab or demo environments there is no error handling included.


1..9 | % {

$VMName = "WS2012-VM0$_"

Write-Host "Create VM $VMName" -BackgroundColor Black -ForegroundColor White
New-VM -Name $VMName -MemoryStartupBytes 2GB -SwitchName VMNET -Path <a href="file://\\sofs01\Share01\&quot; data-mce-href=">\\sofs01\Share01\</a>

Write-Host "Copy VHD..." -BackgroundColor Black -ForegroundColor Green
Copy-item '\\sofs01\Share01\ISOs\Disk\Virtual Hard Disks' -Destination "\\sofs01\Share01\$VMName" -Recurse

Write-Host "Attach VHD..." -BackgroundColor Black -ForegroundColor Green
Add-VMHardDiskDrive -VMName $VMName -ControllerType IDE -ControllerNumber 0 -Path <a href="file://\\sofs01\Share01\$VMName\Virtual Hard Disks\WS2012.vhdx">\\sofs01\Share01\$VMName\Virtual Hard Disks\WS2012.vhdx</a>

Write-Host "Configure Virtual Machine..." -BackgroundColor Black -ForegroundColor Green
Set-VM -Name $VMName -DynamicMemory -MemoryMaximumBytes 4GB -MemoryMinimumBytes 512MB -MemoryStartupBytes 1GB -ProcessorCount 2

Write-Host "Startup Virtual Machine: $VMName..." -BackgroundColor Black -ForegroundColor Green
Start-VM -Name $VMName

}