Archive for October, 2012

My sessions on TEC 2012 with PowerShell and Mythbusting

October 24th, 2012 No comments

Today I was giving my last session on the Technology Experts 2012 in Barcelona. It has been a really good conference and networking. There could have been more attendees in our virtualization track though. I got much good information from the other speakers and they now their stuff!

Here are the other speakers and links to their blogs and twitter accounts:

Aidan Finn aka @joe_elway  (MVP Virtual Machine)

Didier van Hoye aka @WorkingHardInIT (MVP Virtual Machine)

Carsten Rachfahl aka @hypervserver (MVP Virtual Machine)

Hans Vredevoort aka @hvredevoort (MVP Virtual Machine)

Scott Herold aka @vmguru (VMware vExpert)

Mattias Sundling aka @msundling (VMware vExpert)

My first session was about How to handle Hyper-V 2012 with Powershell,

I showed the attendes some nice ways to deploy your virtualization environment, and I also showed how to get yourself locked out in the Active Directory and getting back in, my post done with win server 2008 r2 is still valid for the win 2012

Here is my powershell file with the different powershell scripts I showed. When I get home from Barcelona I will upload my video demo and do an update post with that link so you can see my deployment



And my second session was about mythbusting

The myths i took up was :

  • Core mode
  • Hyper-V used for test/dev
  • AD Dependent Cluster
  • VM time sync
  • VHD Shrink
  • Snapshots
  • Operating systems
And we had some good discussions in the session. I showed that when you want to run Win NT on Win 2012 Hyper-V you can only use powershell to set the flag for CPU old operating systems, Microsoft has removed this setting from the GUI

And as you can see in my screendump you use Set-VMProcessor cmdlet

Get-VM testvm -ComputerName HV01 | Get-VMProcessor | Set-VMProcessor -CompatibilityForOlderOperatingSystemsEnabled $true

Hope to see you next year on TEC 2013!

Categories: Hyper-V, Virtualization, Win2012 Tags:

Raiders of the lost VM´s in Hyper-V 2012 Cluster nodes

October 4th, 2012 2 comments

Inspired by Indiana Jones, I have made a little Powershell function to search cluster nodes for VM´s that has not been cluster enabled. If you create a VM in the Hyper-V manager or the Hyper-V powershell cmdlets, the VM is not highly available by default, even if you added it to a SMB share.

What do I do then, I only use one parameter and that is the cluster name, from this I get the HA – enabled VM´s and then check them for all VM´s registered on the hosts. After this I do a comparison and get a list of the VM´s objects that are not Cluster enabled, this can be pipelined to Add-VMToCluster cmdlet (an alias for Add-ClusterVirtualMachineRole) and you are home safe :-). Of course there might be situations where you want a VM to reside only on one cluster node and not be highly available, Guest Clustering is one case where this might be a reason to not add them to a cluster. And if the VM has the configuration and storage locally you wont be able to add it to the cluster anyway

I can easily with PowerShell get the VM´s that are already HA enabled, but with this command I do not get the other VM´s on the cluster nodes.

Get-VM -ClusterObject (Get-ClusterResource -Cluster hypcl30 | where ResourceType -eq "Virtual Machine")

So if I want to get only the VM´s not cluster enabled, here is the function

   This function search the hosts for VMs tha are not HA enabled
   This function lets you find what VM´s that is running on your hosts and not activated on the virtual machine role on the cluster
   Get-VMNotInCluster -Cluster HVCL30

    Author: Niklas Akerlund /20121004
function Get-VMNotInCluster
        # Name of the Cluster
        $ClusterNodes = Get-ClusterNode -Cluster $Cluster
        $VMsInCluster = Get-VM -ClusterObject (Get-ClusterResource -Cluster $Cluster | where ResourceType -eq "Virtual Machine")
        $VMsTotal = Get-VM -ComputerName (Get-ClusterNode -Cluster $Cluster).Name
        $VMsNotInCluster =@()
        foreach ($VM in $VMsTotal){
                if($VMsInCluster -notcontains $VM){
                    $VMsNotInCluster += $VM

And here is a screendump of it running


And here is when I enable so that all VM´s are Highly Available

Now I do not have so many VM´s in my test environment but in a production environment maybe you can see the potential of knowing that all VM´s on all Clustered nodes are made HA enabled.

Convert Hyper-V vhd to vhdx and back with PowerShell

October 2nd, 2012 No comments

To convert an vhd disk file to vhdx superduper format with PowerShell you just use the cmdlet Convert-VHD (this work only on hyper-v enabled machines). I read Virtual PC Guys post about how to do it in the GUI and wanted to make a small post about how to do it in powershell

Convert-VHD -Path \\win2012-dc01\vms\old.vhd -DestinationPath \\win2012-dc01\vms\new.vhdx -DeleteSource -ComputerName win2012-hv01

And to go back

Convert-VHD -Path \\win2012-dc01\vms\new.vhdx -DestinationPath \\win2012-dc01\vms\old.vhd -DeleteSource -ComputerName win2012-hv01

And here is a screendump

And if I for example want to convert a number of vhd´s

first I create 5 dummy files, of course in the real life you have some files that already are there ready to be converted.

1..5|%{New-VHD -Path .\vhd$_.vhd -SizeBytes 2GB}
Get-VHD -Path C:\vhds\* | %{Convert-VHD -Path $_.Path -DestinationPath ($_.Path + "x") -DeleteSource}

olala look

If you want to convert back to vhd format you need to be sure that it is not bigger than 2040 GB or it will fail. Good luck!

Categories: Hyper-V, Powershell, Virtualization, Win2012 Tags: