Migration script for VM´s moving to Hyper-v 2012 from 2008r2 with VMM

As you might have been reading on my blog about the implementation of the SCVMM 2012 SP1 I have been doing at a customer and the challenges with networking and hosts.

Now the turn has come to migrate those VM´s that reside on the old 2008 R2 cluster to the new shiny Hyper-V 2012 cluster. The approach this time has been to use the VMM and migrate them between the clusters.

VMM 2012 SP1 has some shortcomings when it comes to different configured clusters and their networks. With a bit of crafty PowerShelling I solved that.

So the error was that I could not set the network that I wanted in the migration on the target.. In the VMM Console I get a error and could not continue :

Screen Shot 2013-09-26 at 09.47.36

Then I thought that its maybe an issue in the GUI and can be override in the PowerShell console but NOOOO there exist no parameter for setting the virtual switch :-(

Screen Shot 2013-09-26 at 09.44.49

So I wrote a little script function that first get the VLAN information on the network adapters connected on the VM and then disconnects the virtual network adapters for the VM before migration and then the migration succeeds  :-) and after the migration I connect the virtual network adapters to the VM networks on the new logic switch that correlates to the right VLAN from the source.

from a previous bad experience when trying to migrate VM´s between versions of Hyper-V on VMM with snapshots (Checkpoints) I added a check in the function to not allow migration of VM´s that have active snapshots.

Screen Shot 2013-09-26 at 14.28.54

And here is the script (will do some more thorough testing and add some functionallity but it gives you the idea )


When to select SC Orchestrator over vCenter Orchestrator


I got a question from a customer why they should choose System Center Orchestrator instead of vCenter Orchestrator.

Both products work in the automation field and can do quite much, as they both are extendable and you can develop add-ons, the possibilities are almost endless!

In the case of the System Center Orchestrator, it is included in the System Center suite so if you already use some of the components  and have the licenses in place then you can start automating a lot more.

In the case of vCenter Orchestrator, it is included in the vCenter license that you buy in your vSphere suite.

Both orchestrators are very easy to start working with as they are gui based. the vCenter Orchestrator integrates into the vSphere client and from there you can easily start the wanted workflow. With both you can create workflows/runbooks and let users connect to a web console to kick of the action.

Example of a runbook from SCO


Example of a workflow from vCO

Screen Shot 2013-09-26 at 09.53.23

In both there are possibilities to automate for example Active Directory and users. Onboarding processes when new employees start is an example of an process that often involves quite some manual intervention and benefits from automation. Giving end users and system owners the possibility to create and manage their own virtual machines through a web portal is another example that would offload the IT departments technicians busy day. The list of examples goes on and on…

System Center Orchestrator Architectural overview:

Screen Shot 2013-09-25 at 21.49.06

vCenter Orchestrator Architectural overview:

Screen Shot 2013-09-25 at 21.39.22

Comparison table:

Licensing License required only for endpoints being managed.
No additional System Center licenses are needed for management servers or SQL Server technology.
vCenter standard license, no extra cost
Web console Yes Yes
Third Party Plugin/IP Yes Yes
Custom Plugin/IP development Yes Yes
Manage VMware vSphere Yes Yes
Manage System Center Yes No (not out of the box,requires quite a bit of customization)
Workflow/Runbook templates No Yes
Import/Export Workflow/Runbooks Yes Yes


 So what orchestrator should you go with? Well it depends of course and here is my opinions,

If you have a VMware environment but run mostly Windows Servers and Microsoft applications and already have one or more System Center roles deployed the favor is in the SCO hand as SCO integrates so well with the Microsoft software using the supported Integration Packs and you also can with the VMware IP manage the vSphere environment. The rich amount of activities that the Integration Packs consists of makes it easy to start automating and quickly expand the scope and get some serious automation results in the whole stack! The SCO community helps you a lot when creating runbooks and that with the possibility to import a whole set of runbooks from other IT Pro´s can get your automation goal to be achieved quickly.

If you have a VMware environment and do not use any System Center roles and also have a more diverse load of VM´s with different operating systems, but still want to start automating your environment I would recommend the vCO. One big advantage that the vCO has is that it comes with a wide range of workflows already created and ready to be customized which helps you in the speed to automate.

From a licensing perspective it should be noted that as described in the table, you must have a System Center license on every physical device you plan to automate with System Center Orchestrator. On the virtualization hosts you would use the Windows Datacenter and System Center Datacenter licenses that gives you unlimited VM´s that you can manage. On single physical hosts you must use a System Center Standard license, but as I said above, if you already have another System Center Role you probably have the licensing in place :-). vCenter Orchestrator comes with the vCenter license and there is no extra licensing cost for managing single hosts or Active Directory.

Adding old 2008 R2 Hyper-V Cluster to SCVMM 2012 SP1

At a customer I have been deploying a new System Center Virtual Machine Manager 2012 Sp1.

I was here and deployed their previous solution with VMM 2012 and BareMetal deploy of their hosts. They have been patching and updating the hosts with the integration of wsus in VMM. As I described in an earlier post my first intention was to upgrade the database but after some investigation and trials I decided to start fresh instead…

So with the new installation I wanted to add the old Hyper-V cluster and manage it from the VMM 2012 SP1 and also be able to do migration from the old bare metal deployed hosts and cluster to the new cluster.

After adding the 2008 r2 cluster I had two nodes that did not respond correctly and with the following error

Screen Shot 2013-09-24 at 11.18.17

I tried to restart the VMM-agent on the hosts and that did not help, also tried to reboot the servers, which did not help either.

On one node I also tried to uninstall the VMM agent on the host itself and then to get it back into VMM involved some VMM-database massage, and that did not help either.

So what did help?!

Rebuilding the performance counters as this KB2554336 describes

To rebuild all Performance counters including extensible and third-party counters, type the following commands at an Administrative command prompt. Press ENTER after each command.

Rebuilding the counters:
     cd c:\windows\system32
     lodctr /R
     cd c:\windows\sysWOW64
     lodctr /R

Resyncing the counters with Windows Management Instrumentation (WMI):

Stop and restart the Performance Logs and Alerts service. 
Stop and restart the Windows Management Instrumentation service.

and then restart the VMM agent did solve the above issue and now the hosts reports nicely in VMM

Screen Shot 2013-09-24 at 11.02.45

The hosts had been reporting correctly in the old VMM 2012 so what caused the per counters to go bad, maybe the installation of the new VMM 2012 SP1 agent? If you have had the same issues, please comment this post and share your thoughts!

Updated Add-SCNetworks function for virtual Networks in SCVMM 2012 SP1

Yesterday I described how I could get the networking info out from the VMM before a reinstall or if for another reason you need to get all networks defined.

In an earlier post I described my add networks script and now I have extended it a bit. I have this week made a function of it and also I have changed the import file format to fit the export-file as you get with the earlier post mentioned above. In the function I create a logic network if it is not already in place, that is also done for the network site in the logic network. The logic network created utilize VLAN.

So If you create or export a file with the following columns, Name, Subnet,VlanID you are going to success.

Screen Shot 2013-09-21 at 18.00.22

And when running the function:

Screen Shot 2013-09-21 at 18.05.13

One thing that I wanted also was the possibilty to create just one network with the script and that has also been added.

Screen Shot 2013-09-21 at 18.07.10

The function also handles if you already had setup a network with the same subnet and gives you a warning and do not create that net (maybe you accidentally try to add the same net twice and that is being handled)

Screen Shot 2013-09-21 at 18.11.55

Here is the function

# Add Networks to VMM 
# Niklas Åkerlund 2013-09-16
   Add networks to the logical network and creates virtual networks to them
   this function can take either a csv file as input for creating virtual networks
   Add-SCNetworks -importfile .\networks.csv
   Add-SCNetworks -Name DMZ -Subnet -VlanID 100 -VMHostGroup DMZHosts
Niklas Akerlund 2013-09-16
function Add-SCNetworks
        # Logical Network Name
        $LogicalNetworkName = "LumaNets",

        # Network site name
        # CSV file to be imported
        $ImportFile = " ",

        # Name of the VM network
        $VMHostGroup= "All Hosts"


        $LogicalNet = Get-SCLogicalNetwork -Name $LogicalNetworkName
        # If the logical network not exist, create it
            $logicalNet = New-SCLogicalNetwork -Name $LogicalNetworkName -LogicalNetworkDefinitionIsolation $true -EnableNetworkVirtualization $false -UseGRE $false -IsPVLAN $false
        Write-Verbose $LogicalNet.Name
        $LogicalNet = $LogicalNetwork

    $allSubnetVlan = @()

    # The networks that is going to be imported
    if ($ImportFile -ne " "){
        $vlans = import-csv $ImportFile -Delimiter ";"

        foreach ($vlan in $vlans) {
            # Check that the actual network not already is configured
            if(!((Get-SCLogicalNetworkDefinition).SubnetVLans.Subnet -contains $vlan.Subnet)){

                # First in fabric 
                $LogicalNetDef = Get-SCLogicalNetworkDefinition -LogicalNetwork $LogicalNet -Name $LogicalNetDefName
                $allSubnetVlan = $LogicalNetDef.SubnetVLans    
                $Subnet = $vlan.Subnet 
                Write-Verbose $Subnet
                $SubnetVlan = New-SCSubnetVLan -Subnet $Subnet -VLanID $vlan.VlanID
                $allSubnetVlan += $SubnetVLAN
                    Set-SCLogicalNetworkDefinition -LogicalNetworkDefinition $LogicalNetDef -SubnetVLan $allSubnetVlan
                }else {
                    $LogicalNetDef= New-SCLogicalNetworkDefinition -LogicalNetwork $LogicalNet -Name $LogicalNetDefName -SubnetVLan $allSubnetVlan -VMHostGroup $VMHostGroup

                # Then create VM Networks
                $vmNetwork = New-SCVMNetwork -Name $vlan.Name -LogicalNetwork $LogicalNet -IsolationType "VLANNetwork"
                #$vmSubnet = 
                New-SCVMSubnet -Name $vlan.Name -LogicalNetworkDefinition $LogicalNetDef -SubnetVLan $SubnetVLAN -VMNetwork $vmNetwork
                Write-Host "Subnet $Subnet already exists" -ForegroundColor Red
        # add only a single network
            if(!((Get-SCLogicalNetworkDefinition).SubnetVLans.Subnet -contains $Subnet)){
                # First in fabric 
                $LogicalNetDef = Get-SCLogicalNetworkDefinition -LogicalNetwork $LogicalNet -Name $LogicalNetDefName
                $allSubnetVlan = $LogicalNetDef.SubnetVLans    
                #$Subnet = $IPnet + $Octet
                Write-Verbose $Subnet
                $SubnetVlan = New-SCSubnetVLan -Subnet $Subnet -VLanID $vlanId
                $allSubnetVlan += $SubnetVLAN
                    Set-SCLogicalNetworkDefinition -LogicalNetworkDefinition $LogicalNetDef -SubnetVLan $allSubnetVlan
                }else {
                    New-SCLogicalNetworkDefinition -LogicalNetwork $LogicalNet -Name $LogicalNetDefName -SubnetVLan $allSubnetVlan -VMHostGroup $VMHostGroup

                # Then create VM Networks
                $vmNetwork = New-SCVMNetwork -Name $Name -LogicalNetwork $LogicalNet -IsolationType "VLANNetwork"
                #$vmSubnet = 
                New-SCVMSubnet -Name $Name -LogicalNetworkDefinition $LogicalNetDef -SubnetVLan $SubnetVLAN -VMNetwork $vmNetwork
                Write-Host "Subnet $Subnet already exists" -ForegroundColor Red

It works on both VMM 2012 SP1 and VMM 2012 R2 (preview)

I have looked at Alvin Morales latest blog post about creating networks and will see if I can add some more functionality into my code later on, I think that using parameters instead is a better way. There is always improvements that can be done and the only problem is the time 😉

Report of Logical Networks in SCVMM 2012 SP1

After working with an implementation and upgrade from SCVMM 2012 to SCVMM 2012 SP1 I have been trying to mitigate the issues with the old database and that with the network changes that arrived in SP1 has not been the best way.

Now I have decided to reinstall the VMM database to get a fresh start :-). Yes I lose some history but at least I get a system that will probably work!

I still want to get all the network information that I had in the old db to be able to create new virtual networks with the same network information

Here is an simple PowerShell script that helped me in getting the info

# Easy report of Logical Networks and subnet sites with vlans
# Niklas Akerlund

# Import Module
Import-Module virtualmachinemanager

# all Logical network definitions
$LogicalNetsdef = Get-SCLogicalNetworkDefinition

Foreach ($def in $LogicalNetsdef){
    foreach ($SubnetVlan in $def.SubnetVLans){
                    LogicalNetworkName = $def.LogicalNetwork.Name
         $Obj=New-Object -TypeName PSObject -Property $data  
         Write-Output $Obj   


And when running it I pipe the info to a csv export

Screen Shot 2013-09-20 at 10.29.31

And here is the csv file

Screen Shot 2013-09-20 at 10.54.21

Configure updates for Microsoft products in Windows Update

I have installed a new Windows 2012 Server for System Center VMM SP1 and when I wanted to check what updates that were applicable I found a small issue in the Windows Update and that when configuring it for receiving more updates than just for Windows. After installing the System Center Virtual Machine Manager I definitely want the UR3 for example and that is distributed via Windows update.

By default the setting is as the following screen dump, only Windows updates are being analysed and considered!

Screen Shot 2013-09-17 at 10.44.14


And when pressing the link “Find out more” I get a web page as the following and here you can see that the active-x plugin fails to load

Screen Shot 2013-09-17 at 10.47.11

So to fix this I add the url to trusted sites on IE

Screen Shot 2013-09-17 at 10.47.57

And now when I reload the web page I can agree to the terms of use

Screen Shot 2013-09-17 at 10.48.16

And once that is completed I now get updates for more than just Windows on my server :-)

Screen Shot 2013-09-17 at 10.48.47

Adding multiple Windows hotfixes with wusa and PowerShell

Today I have been exploring a bit in patching  hyper-v hosts with windows updates and hotfixes and when we have a cluster we can use the CAU ( Cluster Aware Updating) that can help you in the process of getting those hotfixes on in a automated fashion but that does not work on single hosts..

In my blog post about checking the hosts for updates and hotfixes I also have added the functionality to download the hotfixes from Microsoft´s servers..

An easy way to add several hotfixes to a host is to use PowerShell with wusa (windows update standalone installer) and it eats .msu files gladly.

But wait, the hotfixes is in a self-extractor exe with at least for some no command-line way to automate, BAD!! So PowerShell to the rescue again, and here on this blog post I found a guy making a PS function to unzip an archive file and it works on the hotfix.EXE also!

Screen Shot 2013-09-13 at 20.18.45
Get-Item .\* | %{Expand-ZipFile -FilePath $_.FullName -OutputPath c:\hotfixes}

And then we can use the WUSA and that wrapped in a foreach with a little while loop to handle that not a  new wusa starts before the preceding one is done as it cannot be run several instances simultaneously (maybe there is a better way to do this of course but this works 😉 )

Screen Shot 2013-09-13 at 14.38.17
Get-Item c:\hotfixes\* | foreach {WUSA ""$_.FullName /quiet /norestart"";while(get-process wusa){Write-Host "Installing $_.Name"}}

And to see if your hotfixes has been installed you can use the following command

Get-HotFix | Where Description -match hotfix

(Get-HotFix | Where Description -match hotfix).count

and of course after installing the hotfixes we need to reboot :-)

Upgrade Windows 8.1 preview to 8.1 RTM with some quirks

Today I wanted to upgrade my Windows 8.1 Preview to the RTM release as it was released yesterday :-)

In the RTM version you cannot upgrade from the preview to RTM  and retain the installed apps without altering the magic cversion.ini file and I am a lazy guy and do not want to install all my apps again after installation ( or just curious to see if it works).

Screen Shot 2013-09-10 at 10.53.56

This is not a supported way of doing things of course, but it is possible.

So I edit the cversion.ini and change the build number to the preview version and voila the option to retain both apps,personal data and settings appear. The cversion.ini file is found under the Image\Sources.

Screen Shot 2013-09-10 at 10.13.58
Screen Shot 2013-09-10 at 10.15.34

And then the upgrade started..

Screen Shot 2013-09-10 at 10.16.41

Although after the installation finishes some application reinstallation occurs and my vpn client wants to be reinstalled with the new version..  well you cannot get everything 😛

Screen Shot 2013-09-10 at 10.35.16

Lync started directly after I logged in but when starting Outlook I had to restart the computer as you can see below and then it also worked nicely :-)

Screen Shot 2013-09-10 at 10.36.55

Live Migrate VM from Windows 2012 to Windows 2012 R2 RTM

Today Microsoft announced the availability of Windows 2012 R2 RTM to Technet/MSDN subscribers.

As I have a Technet subscription with my MCT I had to download right away install and see if it works….

Screen Shot 2013-09-09 at 19.50.16

When I had installed the server I activated the Hyper-V role and the management tools

Screen Shot 2013-09-09 at 19.51.09

In the RTM version of the Hyper-V PowerShell module there is 178 cmdlets and in the preview it was the same number so no new cmdlets have appeared in the latest release.

Screen Shot 2013-09-09 at 20.36.18

I had to test the Live Migration feature and see if it worked to move a VM from a win 2012 Hyper-V to a R2 RTM, I had some issues when trying from the R2 ( I had done the delegation in the AD for kerberos) and when trying from the hyper-v manager it was not totally clear what was wrong:

Screen Shot 2013-09-09 at 21.06.35


and it was in the PowerShell console the error was stated  and as you can see I had forgot to set up a virtual network with the same name as on the source host and that was why the migration failed..

Screen Shot 2013-09-09 at 21.11.42

once that was done the migration worked flawlessly :-)

Screen Shot 2013-09-09 at 21.16.59

Tomorrow I will continue evaluate the RTM release and maybe there will be a new post about my findings then  :-)


Azure and uploading OS VHD´s larger than 127 GB

I have been busy with a newborn baby and not had so much time over for my blog but now I am back at work :-)

I was reading this post about how to convert the vhdx to vhd before uploading your virtual disks to Azure and felt that I needed to explore why the default OS vhd disks on the IaaS role is 127 GB and not larger. There was once a limit that Virtual PC could not utilize larger disks than 127GB on the IDE controller but do not think that Azure runs on Virtual PC 😉

In your local cloud and Hyper-V 2012 you can create VM´s with OS disks connected to the IDE that is larger than 127 GB, although the best practice is to create additional disks and connect them to the SCSI controller instead and install the services there!

So to test first that i could convert a vhdx to vhd and then upload it, and also be able to use it in Azure I used the Convert-WindowsImage.ps1 script to create my test-vm that was 128GB large.

Screen Shot 2013-09-09 at 16.06.56

When uploading with the cmdlet from the Azure PowerShell module it goes quite fast as it only uploads the bits that contains data, not empty blocks.

Screen Shot 2013-09-09 at 15.07.44

And when the upload is finished you create a disk from the uploaded VHD, and as you can see on the screendump it is still 128 GB

Screen Shot 2013-09-09 at 15.16.18

and when I start and connect to it, it show the disk size of 128 GB inside the IaaS VM also!

Screen Shot 2013-09-09 at 15.35.26

One lesson learned is that before uploading your own virtual machine VHD to Azure, and that is to enable remote desktop settings as otherwise you will not be able to connect to the Azure virtual machine once it is running.

Screen Shot 2013-09-09 at 15.53.06