Still some traces of snapshot name in 2012 R2 Hyper-V PowerShell

To align the Hyper-V with System Center VMM Microsoft has changed the Hyper-V manager regarding the snapshots to Checkpoints. I personally had preferred that they changed the naming in VMM to snapshots instead, but that is my opinion and maybe that is because of my background in VMware environments šŸ˜›

checkpointsgui

Although the change has been implemented in the GUI, the PowerShell module has not been updated to reflect this as you can see in my next screendump:

Screen Shot 2013-06-26 at 12.52.22

The cmdlet to take a checkpoint is as it has been in the Hyper-V Powershell module in 2012, Checkpoint-VM.

Upgrading Windows Core Hyper-V from 2012 to 2012 R2

This morning I could read that the R2 preview bits was available to download and of course I had to download and install.

I have installed one Win 2012 R2 with GUI and also I have now tried to upgrade my Windows 2012 Hyper-V core server to R2, as you can see on the screendump below, I had some issues to take care of.

Screen Shot 2013-06-25 at 10.17.31

After evicting it from the cluster and also stopping all VMĀ“s I could continue to upgrade the server, it was really fast (now I have SSD and that does make a difference šŸ˜› ) but still, the feeling is that Microsoft have done some work on making the R2 more rapid, the Powershell console is also more alert and responsive when starting it.

Screen Shot 2013-06-25 at 10.29.13

I will continue to evaluate the Preview and there will probably be some more posts about my findings in the R2 release šŸ™‚

Why create all your virtual machines with Windows 2012/ Windows 8?

0606-Server-2012

As the announcement on Teched there has been several improvements on Hyper-V 2012 R2.

With the Windows Hyper-V Server R2 Ā you can create generation 2 virtual machines but these can only be Windows 2012/ Windows 8 or later. And in this post I will try to give you the insight in why it is important that you set up all your virtual machines from now with 2012 and later.

As several blogs have already created lists of the features in R2 I will just refer to them, Thomas Maurer has a great article and also Aidan Finn (The Irish human Hyper-v blogrobot šŸ˜‰ )

Here are the information about the two features that I want to focus on in this post:

  • Online resizing of VHDXĀ ā€“ You can expand and shrink VHDX files during the virtual machine is running.
  • Generation 2 virtual machinesĀ ā€“ Gen2 VMs are legacy free and based on UEFI. So this means no more emulated devices, boot from virtual SCSI controllers or synthetic network adapters (PXE boot >100MBit) and enables UEFI secure boot as a standard. Supported guest operating systems: 64-bit versions of Windows 8, Windows Server 2012, Windows 8.1 and Windows Server 2012 R2.

So, WoW we can now while the virtual machine runs resize the VHDX, not just extend but also shrink! But there is a limitation!! The vhdx must be connected to a SCSI controller in the virtual machine to be able to utilize this feature! And as you know the system drive (often C:\) in Hyper-V Gen 1 VMĀ“s has to be connected to IDE controller. And yes it is best practice to install the applications and databases and stuff on a separate virtual hard drive that you connect to a SCSI controller but quite often the system drive getĀ“s full with windows patches, logs Ā and also some applications, etc Ā and then you want to be able to extend it and being able to do that online is quite sweet!

I have seen several posts that omit this information and it is quite important to be aware of this and that is why I state above that already now before R2, start creating your virtual machines with Win 2012 so that you when R2 is released and you have it in production can migrate your virtual machines to the Generation 2 VM. Yes I know there are several third party software companies that not have support on 2012 yet with their products. But if they do, then there is no reason to install that on a Windows 2008 R2!

When I get my hands on the R2 bits I will test and see how it works to migrate and will do an post about that so check back šŸ™‚

Windows PowerShell and Desired State Configuration HOL

On Teched 2013 there has been a massive announcement about the future of Windows 2012 R2 and System Center 2012 R2 and there was an session with Jeffrey Snover and Kenneth Hansen about Desired State Configuration DSC and how that works,

Now the Hands-On Lab has been released for DSC and accessible for everyone, this also means that you can access the other parts of PowerShell v4.

Screen Shot 2013-06-12 at 13.05.35

Here is a link to the HOL-310Ā http://channel9.msdn.com/Events/TechEd/NorthAmerica/2013/MDC-H310#fbid=9Ij04Tjn-bt

I have done the lab and it is quite impressive how simple and powerfull it is and being able to keep a desired state of installed/configurered servers with a service on them.

As I was in the lab environment I could not resist to check if there was any new powershell cmdlets for the Hyper-V module in R2

Screen Shot 2013-06-12 at 13.15.44

And with this command you can see that there is 14 new cmdlets in the R2 version of the hyper-v module compared to the 2012 version.

Screen Shot 2013-06-12 at 13.13.01

Here is a list of all the HOL that is available online and probably there will be more added later on.

Adding several networks to your VMM 2012 SP1 with PowerShell

I have created an environment at a customer with bare metal deployment with Hyper-V 2012 and SC VMM 2012 SP1 and in the bare metal profile I am utilizing the logical switches to get a consistent configuration on all hosts and not needing to configure each host every time a new network is going to be set up.

In an earlier post I made a script for adding networks into VMM 2012 but now in SP1 we have logical switches and now also a VM network, the later that adds a bit of complexity in the adding process.

In this case we are using VLANĀ“s and I want to be able to configure and add them without going through the console and all dialogs in the GUI

To get VLAN properly working you also need to check a box in the logical network properties

Screen Shot 2013-06-10 at 22.23.35

So this script asumes that you have a Logical Network already defined and what we do here is adding the subnets in the network sites. If someone finds another way to why I have to add all the subnetVLan objects every time I update the Logical Network Definition, that would be super.. If I do not add all the objects the networks without dependencies are removed.. not so smart

As you can see on this error message when I just try to update with a new Subnet VLAN and not including the other VLAN objects theĀ Set-SCLogicalNetworkDefinition tries to remove and as there is already an VM network it fails. If you look at the script from the gui wizard you will see and understand what I am fuzzing about.

Screen Shot 2013-06-10 at 22.41.01

The structure of the CSV file is as the next screendump and If you already have an excel document or some other information table you could easily change the script to suit your environment and deployment.

Screen Shot 2013-06-10 at 22.34.42

And when running the following PowerShell script it will create not only the subnets in the Network Site but also the VM Networks. Here is the logical network before running the script

Screen Shot 2013-06-10 at 22.57.23

And here is after

Screen Shot 2013-06-10 at 23.02.18

And the VM network, as you can see on the details on the ADM-Servers details it is connected to the VM Subnet with the VLAN 399

Screen Shot 2013-06-10 at 23.03.17
Screen Shot 2013-06-10 at 23.03.33

And here is the script:

# Add Networks to VMMĀ 
#
# Niklas ƅkerlund 2013-06-10
$LogicalNetName = "VMNET"
$LogicalNetDefName = "DevNets"
$ImportFile = "C:\PowerShell\networkvms.csv"

# The networks that is going to be imported
$vlans = import-csv $ImportFile -Delimiter ";"
$LogicalNet = Get-SCLogicalNetwork -Name $LogicalNetName

$allSubnetVlan = @()
foreach ($vlan in $vlans) {
Ā  Ā  # First in fabricĀ 
Ā  Ā  $LogicalNetDef = Get-SCLogicalNetworkDefinition -LogicalNetwork $LogicalNet -Name $LogicalNetDefName
Ā  Ā  $allSubnetVlan = $LogicalNetDef.SubnetVLans Ā  Ā 
Ā  Ā  $Subnet = $vlan.IPnet + $vlan.Octet
Ā  Ā  $SubnetVlan = New-SCSubnetVLan -Subnet $Subnet -VLanID $vlan.VLAN
Ā  Ā  $allSubnetVlan += $SubnetVLAN
Ā  Ā  Set-SCLogicalNetworkDefinition -LogicalNetworkDefinition $LogicalNetDef -SubnetVLan $allSubnetVlan

Ā  Ā  # VM Networks
Ā  Ā  $vmNetwork = New-SCVMNetwork -Name $vlan.Name -LogicalNetwork $LogicalNet -IsolationType "VLANNetwork"
Ā  Ā  New-SCVMSubnet -Name $vlan.Name -LogicalNetworkDefinition $LogicalNetDef -SubnetVLan $SubnetVLAN -VMNetwork $vmNetwork

}

There are some things that I am working on the next version of this simple script, I am going to make it as a function and also some error checking and also verify if the networks already exists or not, that will be posted in another article šŸ™‚

SCVMM DB Backup and cleaning with PowerShell

I have been working on some Virtual Machine Manager deployment and configuring at a customer and after some configuration and misstakes a backup would have been nice. There is a PowerShell cmdlet in the VMM and what it does is to create a DB dump on a path that you specify. Remembering to do this every day that you work with the environment so you can recover is not always so easy and it is often that just after you make a misstake or the system does it for you, the need for backup arrises.

So setting it up with a scheduled job in PowerShell is the way to go, and the script I have also removes the backups after 7 days.

here is the simple script that does the backup and cleaning

# Backup VMM Server
#
# Schedule with either PSScheduledJobs or Task manager
# Niklas Akerlund 2013-06-04
$backupPath = "C:\temp"

ipmo virtualmachinemanager
Backup-SCVMMServer -Path $backupPath

get-item -Path "$backupPath\*" | where {$_.LastWriteTime -lt (get-date).AddDays(-7) -and $_.Name -match "bak"} | Remove-Item

And here is the scheduling that is done with PS Scheduling

backupschedule
$cred = Get-Credential
$dailybackup = New-JobTrigger -Daily -At 10:45PM
Register-ScheduledJob -Name "VMM Backup" -FilePath C:\PowerShell\backupVMM.ps1 -Trigger $dailybackup -Credential $cred

This way you at least have a backup once a day to get you to recover, and talking of recover, if you want to recover the database for the VMM you can use the binary SCVMMRecover.exe and the parameter -Path. You can find the SCVMMRecover in the following path if the VMM is installed with default settings, Ā “C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\bin”

Upgrading to WMF 3.0 on Win 2008 R2 SP1 Hyper-V Core

If you still have some Windows 2008 R2 SP1 Core Hyper-V hosts running and thinking of upgrading to WMF 3.0 there has been some problems with the VMM 2012.

I have a Win 2008 R2 Core SP1 Hyper-V Ā in my VMM 2012 SP1 UR2 and wanted to test if this was still an issue. The main reason for upgrading to the WMF 3.0 is the rebuild of the vmm refresh that is described in this blog post.

First I just tried to run the install file for WMF 3.0 and got the following dialog, and after reading a bit more realizing that it was because I need the .Net 4 as a prerequisite.

notapplicablewmf3

I installed the .Net 4 and there are some things that need to be configured on the Core server before and that is explained on the download page for .Net for Win 2008 R2 SP1 Core

After that It worked to install,

install1wmf3

And after rebooting the host I looked in VMM and also tried some refresh and start/stop on VMĀ“s and setting the host in maintenance mode, everything worked without any issues šŸ™‚

hoststatuswmf3

Not able to set HA on a running VM with SC VMM 2012 SP1

I have described before in blog posts about how to add a running VM to a Hyper-V failover cluster with the PowerShell cmdlets without moving it or turning it off, asuming it already was on a highly available storage such as a CVFS volume or smb 3.0 file share

In my exploration of the virtual machine manager PowerShell module I wanted to test and see if this was also possible in there but I do not succeed, or more correctly maybe should be noted that the SCVMM team has not implemented that for this release šŸ™ what has been implemented is the possibility to make a VM highly available when moving between datastores on a cluster node or from a single hyper-v host to a cluster node. As there is some copying of data it will also take longer time than the below command.

In Hyper-V with failover cluster PowerShell module I can add a VM to the cluster with the following cmdlets without stopping the VM.

sethighavailpshv
Hyper-V\Get-VM vmtest -ComputerName HV02 | Add-VMToCluster -Cluster HVCL30

As you see, the reason why I have added the Hyper-V to the cmdlet is that because in the VMM PowerShell cmdlet there is an alias that is called Get-VM and refers to the Get-SCVirtualMachine and that conflicts with the Hyper-V PowerShell moduleĀ“s Get-VM and I have imported both modules in the same console. I have also imported the failover cluster module in the same console.

If I try to use the Set-SCVirtualmachine vmtest -HighlyAvailable $true I get the following error.

sethighavailvmm

In the VMM Console this option is also greyed out and cannot be set.

isavailablegui

Here is the command to move the VM from one datastore to another and in the same time making it highly available,

movevmworks

I have made a blog post about the issue with Move-SCVirtualMachine not updating the cluster resource and this can be a way to handle this but in my opinion a far more complicated way as you have to move the VM to a new datastore and removing the high availability and then moving it again to another datastore and making it high available again, with a large virtual machine this can take some considerable time when it otherwise just is to run the cluster cmdlet.

New book : Windows 2012 Hyper-V Install and Configuration Guide

HypVConfgInstallgd

Today I bought this book that is written by

  • Aidan Finn
  • Patrick Lownds
  • Michel Luescher
  • Damian Flynn

And in part one I found that Aidan had referred to one of my scripts for moving virtual machine storage without leaving anything behind,

cleaningvNiklas

since the book got into production I have made an update to do some checking and not deleting to much that could happend in the first version!

I feel really honored to be included within a such complete and thorough book about Hyper-V in Windows 2012!

It takes som extra days before it is going to start being delivered in Europe but You can as I by it directly from the Amazon US Kindle store and get it delivered to your App on a chosen device.

Failover Cluster not updated after vm storage migration in VMM 2012 SP1

I was talking to a customer today about an issue they had with their SC VMM 2012 SP1 and when they where doing some storage migrations between their CSV SAN volumes in the Hyper-V cluster.

Screen Shot 2013-03-19 at 22.24.56
Move-SCVirtualMachine -VM (Get-SCVirtualMachine VMtest) -VMHost (Get-VMHost HV02) -Path "C:\ClusterStorage\Volume2" -UseLAN

Everything looks good inside VMM and also the VM works nicely but when looking at the failover cluster manager the resource is not updated which resulted in failure in backup with DPM and probably more issues.

Here is a screendump of the VM in failover cluster manager and also an screendump of the VM in VMM after the migration, as you can see these values does not match

Screen Shot 2013-03-19 at 20.24.47
Screen Shot 2013-03-19 at 20.57.09

There is a way to solve this but that will mean that we have to use the failover cluster and Hyper-V cmdlets. Also should be noted that if we use the failover cluster manager it works so it is a bug in VMM.

So I opened a new PowerShell console and typed the following:

Get-VM VMtest -ComputerName HV02 | Update-ClusterVirtualMachineConfiguration -Cluster HVCL30

And here you can now see that the cluster resource reflects the right data

Screen Shot 2013-03-19 at 22.40.42

There is actually one more solution and that is to remove the VM from the cluster and then add it again but it is easier to just update the cluster virtual machine configuration šŸ™‚

On the management computer I always install the RSAT tools for Hyper-V and also Failover Cluster along with the VMM console to be able to do all management from one place even if I cannot do it all in VMM.