Archive

Archive for the ‘Virtualization’ Category

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

September 21st, 2013 No comments

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
<#
.Synopsis
   Add networks to the logical network and creates virtual networks to them
.DESCRIPTION
   this function can take either a csv file as input for creating virtual networks
.EXAMPLE
   Add-SCNetworks -importfile .\networks.csv
.EXAMPLE
   Add-SCNetworks -Name DMZ -Subnet 192.168.10.0/24 -VlanID 100 -VMHostGroup DMZHosts
.Notes
Niklas Akerlund 2013-09-16
#>
function Add-SCNetworks
{
    [CmdletBinding()]
    Param
    (
        # Logical Network Name
        [Parameter(Position=0)]
        $LogicalNetworkName = "LumaNets",
        
        [Parameter(ValueFromPipelineByPropertyName=$true)]
        [Microsoft.SystemCenter.VirtualMachineManager.LogicalNetwork]
        $LogicalNetwork,

        # Network site name
        [string]
        $LogicalNetDefName="VMnets",
        
        # CSV file to be imported
        [string]
        $ImportFile = " ",

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

    )

    Process
    {
        
    if(!$LogicalNetwork){
        $LogicalNet = Get-SCLogicalNetwork -Name $LogicalNetworkName
        # If the logical network not exist, create it
        if(!$LogicalNet){
            $logicalNet = New-SCLogicalNetwork -Name $LogicalNetworkName -LogicalNetworkDefinitionIsolation $true -EnableNetworkVirtualization $false -UseGRE $false -IsPVLAN $false
        }
        Write-Verbose $LogicalNet.Name
    }else{
        $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
                if($LogicalNetDef){
                    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
            }else{
                Write-Host "Subnet $Subnet already exists" -ForegroundColor Red
            }
        }
    }else{
        # 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
                if($LogicalNetDef){
                    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
            }else{
                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

September 20th, 2013 No comments

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){
        $data=[ordered]@{
                    LogicalNetworkName = $def.LogicalNetwork.Name
                    Name=$def.Name
                    Subnet=$SubnetVlan.Subnet
                    VlanID=$SubnetVlan.VLanID
                }
         $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

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

Configure updates for Microsoft products in Windows Update

September 17th, 2013 No comments

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

Categories: SCVMM, Virtualization, Win2012 Tags:

Adding multiple Windows hotfixes with wusa and PowerShell

September 13th, 2013 No comments

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

check-hotfixesinstalled

Get-HotFix | Where Description -match hotfix

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

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

Live Migrate VM from Windows 2012 to Windows 2012 R2 RTM

September 9th, 2013 No comments

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  :-)

 

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

Azure and uploading OS VHD´s larger than 127 GB

September 9th, 2013 No comments

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

 

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

Rescue Missing VM with unmerged snapshots on HyperV/VMM

August 26th, 2013 1 comment

Today I have been at a customer and helping them in a SC VMM issue where the VM went missing during a storage migration from one CSV volume to another. We are working on a project to upgrade this environment from Hyper-V 2008 R2 Sp1 to 2012 and VMM 2012 SP1 but this issue is from the VMM 2012.

felvmmsm

On the vm there were three avhd files from snaphots taken at different times and the files was quite big.. the virtual machine original vhd was 53 GB and the snapshot differencing disks where about 40 GB each. So quite a bit of data to merge. The customer removed the snapshots but was a bit too eager to start the move so the vm had not merged the snapshots files before they started the migration.

During the migration the VMM server lost connection for a very short moment to the host and the result was that the vm got missing in the VMM console and also in the Hyper-V manager. The job had removed the VM´s configuration file but not moved it to the new location so what was left in the virtual machine folder was just the vhd and avhd files.

To find which avhd file that was the latest and find the snapshot-chain we used the “inspect disk”  and “inspect parent” in Hyper-V manager, in Win 2008 R2 Sp1 it does not show the avhd file by default so you have to copy and paste the file name and then it works. As the files was in a merge process it was not obvious which file was the latest, in a normal case it is quite obvious to see in the date properties of the avhd files.

Screen Shot 2013-08-26 at 11.46.08

When we found which was the right avhd file we created a new VM and attached the avhd file, same procedure as with the inspect disk, copy and paste the file name in the field. If you would take the wrong avhd file and start the VM the differencing chain would break and all changes in the files after would be lost!

Now We could start the VM and verify that we got all data until the latest snapshot and that the customers user not had lost any data! As it now was a new VM with a new network card we had to enter the IP settings on that network connection.

The easiest way we thought of to get the VM to merge the avhd´s was to use the “Clone” feature in the VMM console.

Screen Shot 2013-08-26 at 13.09.12

And when the clone of the VM was finished that job had also merged the disks and the virtual machine started without any errors and avhd files :-)

I have made two blog posts a while ago about checking if a vm have snapshots before migrating it to another cluster and also a post about how you can extend the console with info on what virtual machines have snapshots to easily have control!

I have said it before and will emphasize it again, do not use snapshots as backup solution and remove them as soon as you are done as they do impact on performance !

I look forward to when we have the environment on hyper-v 2012 where the live-merge feature exist and also later the R2 feature with the live clone!

Categories: Hyper-V, SCVMM, Virtualization Tags:

Shrinking the C: System VHD disk in Azure IaaS

August 21st, 2013 5 comments

Today I have been working with Azure and the disk size. In our lab environment we started out when the Azure Iaas role was still in preview and it had a limit that not until now have appeared as a problem. The system VHD in the preview version was only 30 GB and now when the c:\windows\winSxS folder has grown with patches and install files to about 14 GB the volume is beyond full :-/ and yes the SQL service running on the server is installed on another partition..

And as you can read on this blog post it is not an option to try to remove the files inside the winSxS folder!

The different options on how to do an resize of an disk in an Azure Iaas VM when doing a search is quite cumbersome but I found this guy Maarten Balliauw that made a console app that can fix the stuff and this without installing new VM´s or downloading the VHD.

Now to test how to do it I created a new VM and this get a OS disk with 127 GB and I wanted it to be 30 GB so I had to shrink it. The binary that Maarten have does not include the latest addition with the shrink option, so I asked my colleague to compile it for me as I do not have Visual Studio installed (at least not yet), Thank you Tim!

UPDATE -> Download Tims compiled binary here : shrinkAzure

So to do a shrink with the latest source and a friend with a compiler.

  • Shrink the partition with powershell or disk management tool (if you do not the OS partition will be corrupt if shrink the vhd beyond this)
  • Shutdown the VM
  • Delete the VM -or- detach the disk if it’s not the OS disk
  • Delete the cloud service if you have created it to be able to create a new with the same name
  • In the Windows Azure portal, delete the disk (retain the data!) do that the lease Windows Azure has on it is removed
  • Run WindowsAzureDiskResizer
  • In the Windows Azure portal, recreate the disk based on the existing blob
  • Recreate the VM  -or- reattach the disk if it’s not the OS disk
  • Start the VM

So I start shrinking the volume inside the Azure VM. As you might notice I have shrink it to just below 30 GB (30GB -1MB)

Screen Shot 2013-08-21 at 14.42.25

And then I have a volume that looks like this in the disk manager

Screen Shot 2013-08-21 at 14.43.05

Next step is to delete the VM and also the delete the disk (retain data) and as Maarten says I can then use his tool, if I do not delete the disk from the Iaas it will fail. And here I enter 30 GB disk size, and if I would not have done the volume just 1 MB below 30GB I get a corrupt OS volume, the tool does not check the volumes inside the VHD..

Of course I could have done a VHD size of 31 GB but this was just for testing and seeing what happens.. I did also remove the Cloud Service so that I could use that name after I was done to get the old url to the new VM.

Screen Shot 2013-08-21 at 14.52.50

Now it is time to re-create the virtual disk and then the virtual machine..

Screen Shot 2013-08-21 at 14.54.07

And then when I started the virtual machine and connect to it, the size of the disk is 30 GB

Screen Shot 2013-08-21 at 15.05.58

I am looking forward to the day that Azure runs on Windows 2012 R2 Hyper-V and the VM´s in the Iaas role can be configured with Gen2 and you can change the vhdx size on the fly when the VM is running :-)

Categories: Hyper-V, Virtualization, Win2012 Tags:

VMware to Hyper-V Migration with MAT and my addons

August 15th, 2013 2 comments

Today I was on Sommarkollo at Microsoft Sweden and speaking on the event and this was the last of two sessions about the MAT (Migration Automation Toolkit).

This automation tool that I first got to know about at MMS 2013 in Las Vegas (sadly it looks like there will be no more MMS :-( but that is another story ) in the session held by “Migration Mark” and Matt McSpirit WS-B325 and there in the video about 41 minutes into I ask about how the MAT take care of IP addresses on the migrated VM´s and they answered me that is not part of the MAT yet! And well I would say that this would be quite painful to migrate 100-200 VM´s with this automation tool and still have to enter IP settings for each migrated vm manually!!

But I have an example on how that can be done, I have not integrated it into the MAT scripts yet but it automates the collection of not just the IP addresses but also dns,subnet and gateway.

The information is available via the PowerCLI from the vCenter and here I show you how you can collect all that info after you have got the migration list

# Collect Networking info from VM´s 
#
# Niklas Akerlund / 2013-07-01
if(!(Get-PSSnapin "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue)){
    Add-PSSnapin "VMware.VimAutomation.Core"
}
$MigVMs = Get-Content "d:\mat\vmlist.txt"
$VMNetConf = @()
Connect-VIServer vCenter.vniklas.com
remove-module Hyper-V -ErrorAction SilentlyContinue

foreach ($MigVM in $MigVMs){
     $VM = Get-VM $MigVM.Split(".")[0]
     #write-host $VM
     #$VM = Get-VM $VM 
     $VMNics = Get-VMGuestNetworkInterface $VM | where {$_.IP -ne $null -and $_.IPPolicy -eq "Static"}
     foreach ($VMNic in $VMNics){
         $VMNetAdapter = Get-NetworkAdapter -VM $VMNic.VM -Name $VMNic.NetworkAdapter
          $obj = [PSCustomObject]@{
                        VMName = $VM.Name
                        NetworkName = $VMNetAdapter.NetworkName
                        IP = $VMNic.Ip
                        Subnet = $VMNic.SubnetMask
                        DNS = [string]$VMNic.Dns
                        GW = $VMNic.DefaultGateway
                        }
          $VMNetConf +=$obj
     }
}

$VMNetConf | Export-csv -Path d:\mat\vmniclist.txt -NoTypeInformation -NoClobber -UseCulture

Here you can see the csv file after it has run in my test environment, one thing that I will extend with after discussing with some folks is the vlan number the port group the vm is connected to so that can be configured on the other side also.

Screen Shot 2013-08-15 at 23.30.25

And then I also with the possibility that there is in Hyper-V 2012, configure the network on the guest from the host, this requires that the virtual machine has the latest integration components installed. Ravikanth has done a blog post about how his function, I have added the possibility to run it from a remote computer

# Set-VMNetworkConfiguration
# Orginial by Ravikanth http://www.ravichaganti.com/blog/?p=2766
#
# Added computername to remotly set IP to guest from hosts
# Niklas Akerlund
Function Set-VMNetworkConfiguration {
    [CmdletBinding()]
    Param (
        
        [Parameter(Mandatory=$true,
                   Position=1,
                   ParameterSetName='DHCP',
                   ValueFromPipeline=$true)]
        [Parameter(Mandatory=$true,
                   Position=0,
                   ParameterSetName='Static',
                   ValueFromPipeline=$true)]
        [Microsoft.HyperV.PowerShell.VMNetworkAdapter]$NetworkAdapter,
        
        [Parameter(Mandatory=$true,
                   Position=2,
                   ParameterSetName='DHCP',
                   ValueFromPipeline=$true)]
        [Parameter(Mandatory=$true,
                   Position=5,
                   ParameterSetName='Static',
                   ValueFromPipelineByPropertyName=$true)]
        [String[]]$ComputerName=@(),

        [Parameter(Mandatory=$true,
                   Position=1,
                   ParameterSetName='Static')]
        [String[]]$IPAddress=@(),

        [Parameter(Mandatory=$false,
                   Position=2,
                   ParameterSetName='Static')]
        [String[]]$Subnet=@(),

        [Parameter(Mandatory=$false,
                   Position=3,
                   ParameterSetName='Static')]
        [String[]]$DefaultGateway = @(),

        [Parameter(Mandatory=$false,
                   Position=4,
                   ParameterSetName='Static')]
        [String[]]$DNSServer = @(),
         
        [Parameter(Mandatory=$true,
                   Position=0,
                   ParameterSetName='DHCP')]
        [Switch]$Dhcp
        
    )

    $VM = Get-WmiObject -Namespace 'root\virtualization\v2' -Class 'Msvm_ComputerSystem' -ComputerName $ComputerName | Where-Object { $_.ElementName -eq $NetworkAdapter.VMName } 
    $VMSettings = $vm.GetRelated('Msvm_VirtualSystemSettingData') | Where-Object { $_.VirtualSystemType -eq 'Microsoft:Hyper-V:System:Realized' }    
    $VMNetAdapters = $VMSettings.GetRelated('Msvm_SyntheticEthernetPortSettingData') 

    $NetworkSettings = @()
    foreach ($NetAdapter in $VMNetAdapters) {
        if ($NetAdapter.Address -eq $NetworkAdapter.MacAddress) {
            $NetworkSettings = $NetworkSettings + $NetAdapter.GetRelated("Msvm_GuestNetworkAdapterConfiguration")
        }
    }

    if ($Dhcp) {
        $NetworkSettings[0].DHCPEnabled = $true
    } else {
        $NetworkSettings[0].DHCPEnabled = $false
        $NetworkSettings[0].IPAddresses = $IPAddress
        $NetworkSettings[0].Subnets = $Subnet
        $NetworkSettings[0].DefaultGateways = $DefaultGateway
        $NetworkSettings[0].DNSServers = $DNSServer
        $NetworkSettings[0].ProtocolIFType = 4096
    }

    $Service = Get-WmiObject -Class "Msvm_VirtualSystemManagementService" -Namespace "root\virtualization\v2" -ComputerName $ComputerName
    $setIP = $Service.SetGuestNetworkAdapterConfiguration($VM, $NetworkSettings[0].GetText(1))

    if ($setip.ReturnValue -eq 4096) {
        $job=[WMI]$setip.job 

        while ($job.JobState -eq 3 -or $job.JobState -eq 4) {
            start-sleep 1
            $job=[WMI]$setip.job
        }

        if ($job.JobState -eq 7) {
            write-host "Success"
        }
        else {
            $job.GetError()
        }
    } elseif($setip.ReturnValue -eq 0) {
        Write-Host "Success"
    }
}

And here is the script that I run to configure the VM´s after the MAT has done the conversions, and yes as Mark says about MAT, there is room for improvements here also of course, As you can see I start with injecting the latest integration components into the VM, the sleep cmdlet is used to get the vm fully booted and integration components installed and then an reboot inside the VM.

# Configure and set VM after Conversion
#
# Niklas AKerlund / 2013-07-01

# Function import
. .\Set-VMNetworkConfiguration.ps1

$VMNICs = Import-CSV -Path D:\mat\vmniclist.txt -Delimiter ";"
$ConvertedVMs = Get-Content -Path D:\mat\VMlist.txt

# Configure each vm before starting
foreach ($ConvertedVM in $ConvertedVMs){
    $VM = Get-VM $ConvertedVM.Split(".")[0]
    write-host $VM.Name
    #patch each VM with latest Integration Tools
    $virtualHardDiskToUpdate =($VM | Get-VMHardDiskDrive).path
    $integrationServicesCabPath ="C:\Windows\vmguest\support\amd64\Windows6.x-HyperVIntegrationServices-x64.cab"

    #Mount the VHD
    $diskNo=(Mount-VHD -Path $virtualHardDiskToUpdate –Passthru).DiskNumber

    #Get the driver letter associated with the mounted VHD, note this assumes it only has one partition if there are more use the one with OS bits
    $driveLetter=(Get-Disk $diskNo | Get-Partition | where Size -GT 100MB).DriveLetter

    #Check to see if the disk is online if it is not online it
    if ((Get-Disk $diskNo).OperationalStatus -ne 'Online'){Set-Disk $MountedVHD.Number -IsOffline:$false -IsReadOnly:$false}

    #Install the patch
    Add-WindowsPackage -PackagePath $integrationServicesCabPath -Path ($driveLetter + ":\")

    #Dismount the VHD
    Dismount-VHD -Path $virtualHardDiskToUpdate
    
    Start-VM -VM $VM

    Start-Sleep -Seconds 300
    
    # Wait for the Integration components being installed and the server reboot (reboot requires interaction or automatic script inside VM or you will have to do an unclean poweroff

    Start-VM -VM $VM

    # check that the migrated VM actually has ic that responds 
    do {
        $notok = Get-VMIntegrationService -VM $VM | Select -First 1 | where PrimaryStatusDescription -eq "OK"
    } while( $notok -eq $null)

    # COnfigure NICs
    foreach ($VMNic in $VMNICs){
        write-host "Configuring" 
        if($VMNIC.VMName -eq $VM.Name){
           if(!(Get-VMNetworkAdapter -VM $VM)){
               $VMNetAdapter = Add-VMNetworkAdapter -VM $VM -SwitchName $VMNic.NetworkName -Passthru
               $VMNetAdapter | Set-VMNetworkConfiguration -IPAddress $VMNic.IP -DefaultGateway $VMNic.GW -Subnet $VMNic.SubnetMask -DNSServer $VMNic.Dns -ComputerName HV03
         
           }else {
           
               Connect-VMNetworkAdapter -VMName $VM.Name -SwitchName $VMNic.NetworkName
               $VMNetAdapter = Get-VMNetworkAdapter -VM $VM
               write-host "connecting $VMNic.NetworkName "
               $VMNetAdapter | Set-VMNetworkConfiguration -IPAddress $VMNic.IP -DefaultGateway $VMNic.GW -Subnet $VMNic.Subnet -DNSServer $VMNic.DNS -ComputerName HV03
          }
        }
    }

}

And after running as you can see in the Hyper-V manager I have the right IP on the VM (and if you check inside the VM, you will see that the dns,subnet and gateway also has been set correctly.

Screen Shot 2013-08-15 at 23.38.27

Successfully Migrate Gen1 VM to Gen2 on Windows HyperV R2

August 8th, 2013 No comments

I have written an article about why it was important to start installing your VM´s as Windows 2012 and also I mentioned it in my article about resizing vhdx on the new Windows 2012 R2 and I did not have a solution how to migrate the VM.

Today I have successfully migrated a Generation 1 VM with Windows 2012 standard to a Generation 2 VM on a Windows 2012 R2 Hyper-V host. This involved a third party software from Vision Solutions called Double-Take Move.

What I did was installing a Windows 2012 on a Generation 1 VM and updated to the latest integration components. I configured a static IP, changed server name and added it to the domain. Then I also added some files and installed the Web Server role with a custom webpage to see that the service responded after the fail-over.

Screen Shot 2013-08-08 at 10.49.44

Last step was to install the Double-Take Move software.

Screen Shot 2013-08-08 at 13.55.27

And for the target I created a Generation 2 VM and installed Windows 2012 and also here updated to latest integration components. In this VM I only installed the Double-Take Move software. The VM was configured with DHCP and no domain join.

Then It was time to create a Move-Job and after a full sync I could do a failover:

Screen Shot 2013-08-08 at 13.54.57

And as you can see on the following screendump, the Gen2 VM have got the right settings. And of course my web page responded as expected!

Screen Shot 2013-08-08 at 13.14.17

And here is a comparison on the device manager between the two and as you can see that the IDE is gone in the G2.

Screen Shot 2013-08-08 at 14.13.43

The Double-Take Move is a powerful tool and it requires a license to work. They also have integration with System Center VMM and Orchestrator to automate a large scale migration. Now I just tried to migrate inside a hyper-v host between two VM´s but I could have done a migration from a VMware environment or a physical server instead :-).

After working a lot with NetIQ Platespin Migrate (which has unfortunately been lagging behind in the development and support for newer os) I now have a positive experience of the Double-Take software and the easy to use and start migrating!

Categories: Hyper-V, Virtualization, Win2012 Tags: