Archive

Archive for the ‘Virtualization’ Category

Converting VHD´s to VHDX in SCVMM 2012 SP1 with PowerShell

October 4th, 2013 1 comment

I have in an earlier post described my little PowerShell function to migrate VM´s from a Windows 2008 R2 cluster to a new Windows 2012 Hyper-V cluster in VMM.

As it is a best practice to convert your VHD´s to VHDX I wanted to do that with SCVMM 2012 Sp1 also. It is a small detail that you need to be aware of when doing it in the VMM console, it does not remove the old VHD file from the datastore and in the GUI it is no checkbox for that either. This is the case for both VMM 2012 SP1 and R2 Preview. And if you start converting several VM´s VHD´s there is a possibility that your datastore will become full quite fast and that is not so good!

Screen Shot 2013-10-04 at 14.39.44

And on the folder where the virtual harddisk resides you can see that the vhd still exists..

Screen Shot 2013-10-04 at 14.57.15

In the PowerShell cmdlet Convert-VirtualDiskDrive there is a parameter -deletesource that removes the VHD once the conversion has completed :-)

So I have made a PowerShell function if you want to convert all your VHD´s on the virtual machine.

Good luck in getting the Hyper-V 2012 environment in the best shape ever before moving to 2012 R2!

New PowerShell VM Inventory Script for SCVMM 2012 SP1/R2

September 29th, 2013 14 comments

about 1 1/2 years ago I made a script for Inventory Reporting in SCVMM 2012 and now I have been working on an update that supports VMM 2012 Sp1 and R2, there have been some changes in the cmdlets so now it was time to refresh it and add some information.

In VMM 2012 R2 the possibility to get the IP address has been added so I utilize that from VMM, if you are using the SP1 version I can get the IP address from the Hyper-V PowerShell module and the cmdlet Get-VMNetworkadapter, that works only on Hyper-V 2012 Hosts and the Integration components have to be updated. The function reports the number of NIC´s and VHD´s but not show all, I have chosen to just add one virtual NIC and three virtual hard disks in this, that can be altered if you want and just add in the hash table.

In this new function I have added a switch parameter that lets you select if you want a html/csv report or just work with the objects that comes out of it when running :-)

To use it you can just use one of several ways with parameters

Screen Shot 2013-09-29 at 22.38.05

 

And here is the script function

And here is an example of the csv report, and yes it is much info, the CSV can be scrolled quite a bit :-)

Screen Shot 2013-09-29 at 22.27.45

You can select what you want included in the report by just using the function and pipe it to Export-CSV

 

 

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

September 27th, 2013 1 comment

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 )

 

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

September 24th, 2013 No comments

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):
     WINMGMT.EXE /RESYNCPERF

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!

Categories: Hyper-V, SCVMM, Virtualization Tags:

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: