Wednesday, July 27, 2011

Windows Server 2008 Hyper-V Geographically Dispersed Cluster with IBM XIV Storage iSCSI

Here is a paper that I worked on at my team at Microsoft. The Enterprise Engineering Center ( has a IBM XIV array that we used with the other array on campus.

Windows Server 2008 Hyper-V Geographically Dispersed Cluster with IBM XIV Storage iSCSI

You can find more info on the Tunnel used in this whitepaper at

How to create differencing disk VM from template on SCVMM 2012 via powershell

This quick post will provide an example of how to create a Virtual Machine (VM) based off an VMM template that utilizes differencing disks. 

This is special because VMM does not support this natively.  So you have to contact the target HyperV host (via WMI) to create the Diff disk.  In addition to need to make sure that the HyperV host has the parent VHD already in place. 

The Powershell cmdlet below does the following
  1. Looks up the specified Hardware profile
  2. Looks up the specified template (this is used to get the parent VHD location/name)
  3. Looks up info on the specified target HyperV host (so we can find the placement drive)
  4. Checks to see if the ParentVHD already exists on the HyperV hosts Placement Drive
  5. If the VHD does not exist it copies it to the HyperV host
  6. Creates Diff Disk via WMI on hyperV host pointing to parent VHD
  7. Creates the VM via the New-SCVirtualMachine cmdlet using the UseLocalVirtualHardDisk command. (this tells VMM to allow Diff disks).
It can be downloaded from
    param($VMName,$TemplateName = "Windows Server 2008 R2 SP1 Enterprise", $HardwareProfileName = "ServerHardware", $VMMHost = "SCVMM",$targethostname = $null)
    $Err = 0
    If ($VMName -eq $null)
      Write-Host "`nERROR: Incorrect arguments" -foregroundcolor red -backgroundcolor black
       Write-Host "`nREQUIRED ARGUMENTS:" -foregroundcolor cyan
       Write-Host "`n   -VMName `"Name of the VM to create`"" -foregroundcolor cyan
       Write-Host "`n   -TemplateName `"Name of the VMM Template`"" -foregroundcolor cyan
       Write-Host "`n   -HardwareProfileName `"Name of the VMM Hardware Profile to use with the template`"" -foregroundcolor cyan
       Write-Host "`n   -VMMHost `"VMM Computername`"" -foregroundcolor cyan
       Write-Host "`n   -targetHostname `"Computername of HyperV host to target`"" -foregroundcolor cyan
      Exit $Err
    function CreateDiffDiskOnHost
                    param([string]$hostComputerName, [string]$childPath, [string]$parentPath)
                    #get the image mgmt service instance for the host computer
                    $VHDService = get-wmiobject -class "Msvm_ImageManagementService" -namespace "root\virtualization" -computername $hostComputerName
                    #create a differencing disk from the base disk
                    $Result = $VHDService.CreateDifferencingVirtualHardDisk($childPath, $parentPath)
    function TestFileLock {
        ## Attempts to open a file and trap the resulting error if the file is already open/locked
        param ([string]$filePath )
        $filelocked = $false
        $fileInfo = New-Object System.IO.FileInfo $filePath
        trap {
            Set-Variable -name locked -value $true -scope 1
        $fileStream = $fileInfo.Open( [System.IO.FileMode]::OpenOrCreate, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None )
        if ($fileStream) {
        $obj = New-Object Object
        $obj | Add-Member Noteproperty FilePath -value $filePath
        $obj | Add-Member Noteproperty IsLocked -value $filelocked
    write-host "VMName is $VMName"
    write-host "Template is $TemplateName"
    write-host "Hardware Profile is $HardwareProfileName"
    write-host "VMMHost is $VMMHost"
    write-host "Target Host is $targethostname"
    $guid = [guid]::NewGuid()
    write-host "Lookup the base hardware Profile $HardwareProfileName"
    $HardwareProfile = Get-SCHardwareProfile -VMMServer $VMMHost  | where {$_.Name -eq $HardwareProfileName}
    if ($HardwareProfile -eq $null)
            write-host "Failed to lookup HardwareProfile $HardwareProfileName"  -foregroundcolor red -backgroundcolor black
         EXIT 1
    write-host "Getting information for template $TemplateName"
    $Template = Get-SCVMTemplate -VMMServer $VMMHost  -All | where {$_.Name -eq $TemplateName}
     if ($Template -eq $null)
            write-host "Failed to lookup Template $TemplateName"  -foregroundcolor red -backgroundcolor black
         EXIT 1
    #Get the VHD info for the template
    $VHD =  Get-SCVirtualharddisk | where {$_.Name -eq $template.VirtualDiskDrives[0].VirtualHardDisk}
    write-host "Template VHD Path " $VHD.SharePath
    if ($targethostname -eq $null)
        write-host "Invalid targethostname"  -foregroundcolor red -backgroundcolor black
        exit 1
    $vmhost = Get-SCVMHost $targethostname
    $vmHostPath = [string]$vmhost.vmpaths
    write-host "Target VMHost: "  $
    write-host "Target Drive: "  $vmhost.VMPaths
    $remotePath = "\\" + $ + "\" + $vmHostPath.substring(0,1) + "$\" + []::GetFileName($VHD.SharePath)
    "Checking to see if Parent VHD exists on HV Host Drive"
    "RemotePath: $remotePath"
    if (Test-Path $remotePath)
     "Parent VHD already exists on HV Host"
     "$RemotePath does not exist, going to Copy"
    "Creating Diff Disk"
    $targetVHDPath = $vmHostPath + $VMName + ".vhd"
    $ParentVHDPath = $vmHostPath + []::GetFileName($VHD.SharePath)
    CreateDiffDiskOnHost "$vmhost" "$targetVHDPath" "$ParentVHDPath"
    Start-Sleep -s 20
    $targetVHDRemotePath = "\\" + $ + "\" + $vmHostPath.substring(0,1) + "$\" + $VMName + ".vhd"
    if (Test-Path $targetVHDRemotePath)
     "Diff Disk Created at:$targetVHDRemotePath"
     "$targetVHDRemotePath does not exist yet.  Sleeping for a few"
     Start-Sleep -s 30
        if (Test-Path $targetVHDRemotePath)
            "Disk was created."
            write-host "Failed to find VHD $targetVHDRemotePath after sleep, exiting" -foregroundcolor red -backgroundcolor black
            exit 1
    #Set a random startup delay to reduce VM startup IOPs overload
    $startDelay = Get-Random -minimum 1 -maximum 30
    $lockstate = TestFileLock "$targetVHDRemotePath"
    if ($lockstate.IsLocked)
        "File locked, sleeping"
        Start-Sleep -s 30
    $mv = move-SCvirtualharddisk -Bus 0 -Lun 0 -IDE -path $targetVHDPath  -jobgroup $guid
    $description = $template.tag
    New-SCVirtualMachine -Name $vmName -VMHost $vmHost -VMTemplate $template -UseLocalVirtualHardDisk -HardwareProfile $HardwareProfile -ComputerName $vmName -path $vmHostPath -delaystartseconds $startDelay  -Description "$description" -mergeanswerfile $true -BlockDynamicOptimization $false -StartVM -JobGroup "$guid" -RunAsynchronously -StartAction "AlwaysAutoTurnOnVM" -StopAction "SaveVM"

    Monday, July 18, 2011

    Home Circuit Power Monitoring

    Ever wonder why your home power bill is so high?   Or just want to know how much power you use in various parts of your house through the whole day? 
    I have one of the Blue Line Power monitors for Microsoft Hohm (  This product did not allow me to see how much a single room or circuit was using.  It was a start. 

    I have the LCD display in my living room near the TV so that I can quickly see how much energy my home is consuming.

    Microsoft Hohm Data (Sunday, Got up at ~9am)

    For my 30th birthday I got all the parts I need to do per-circuit power monitoring for my whole house. By doing branch circuit monitoring I can answer many questions about my enery usage.

    • What does this mean?  I can tell you things like:
    • Exactly how much does it cost me for it to run
      • How much power does my house use when I turn off all my normal items
    • Leaving things like laptop and cell phone chargers on
      • How much does it cost me to run my AC in the summer?  Is it worth leaving on all day or turning on just when I get home
    • Or in my case thanks to Insteon I can turn it on before I leave work!
    The Solution:
    I got the ECM1240 system from  Specifically the PP3-200-X (
    I installed solid core CTs on each breaker on my home circuit panel.  


    To hold the ECM1240 brains I installed a PVC box just next to my main panel to hold all the low voltage items.  

    The ECM1240 allows me to view my data in real-time via the website, read the data from google powermeter or push it into my own data collection environment.
    The CONS about the 1240 system are:
    1. The software to manage the 1240 collection devices has more bugs in it than Windows ME. It crashes often and overall is a piece of junk.
    2. The solution by default only supports Google powermeter not
      • While google powermeter has its ups one thing that is has a serious issue with it is the User interface sucks
      • The ability to export the data into CSV format from google is nice. Not an option on
      • The ability to share access to my power data from google is nice. Not an option on
    3. With Google Powermeter and being retired I will have to find a new way to view my power data.

    Google Power Meter Data Data

    Controller 1
    Controller 2
    Controller 3

    Sunday, July 17, 2011

    The Delta Touch2O faucet

    How I love my Delta Touch2O faucet.

    We had to have an additional hole drilled so that we could install it. Most of the videos/blogs talk about how it is a big pain to install. But I found it quite simple. We don't have a lot of room under the sink but i was able to get it done by myself in less than 1 hour.

    Also we read that there are issues with the batteries draining quickly and needing replacements often. We have had the same batteries installed for over 1 year now. It is used everyday by 3 sometimes 4 people.

    I cannot wait to get one for the bathrooms!

    Managing Microsoft IIS, Active Directory and DNS from .net

    Update 7/17/2011:  New links

    This code was one of my first coding project from 11-10-2006

    Today I am posting sample code on how to manage IIS 6 and Active directory using ADSI in VB.NET.
    And managing DNS (creating zones, records and enumeration) using WMI in VB.NET.
    There are four separate projects. 
    This code is posted as-is!  It is to be used as a sample on how to do the work.  It is not intended to be used in production! - ADSI management of IIS 6 Sites and AppPools - WMI management of Microsoft DNS Zones and Records ADSI management of Active Directory contacts, Groups, Users, Recipient Policies, Accepted Domains objects (Exchange 2007) - C# code on generating IIS SiteID

    10 Years from last post

     Well world!   After the last almost 10 years I have been up to a few things in life and work.  Most recently I was working at Microsoft on ...