Wednesday, August 14, 2013

Generate DR Portgroups for SRM with Powercli

The Problem

Today I was working at a customer site doing a SRM setup and was hit with a situation. The customer had setup a new DHCP vlan and portgroup at their DR site for SRM and wanted to fail over all their Production Servers to this network.
 As we went through their resource mappings and layout we came to an issue were a many to one mapping for Prod to DR for network resources was good but fail back from DR to Prod was not possible. This was because a one to one relationship was needed.

The Solution

In order to work around this I recommended to the client we setup a virtual port group for each prod network.  This new label at DR would be composed of the Prod virtual portgroup and DR DHCP network (i.e. VLAN113-DR-DHCP). Each of these new virtual portgroups will have the same VLAN ID for their newly created DHCP network.

Script was born

 So that being said, I went to my trusty script editor and started to write this powershell script that will take all production networks and apply them to DR esxi hosts. This script is for use with standard vswitch. Hope people find it useful. This will be handy script for adding new virtual portgroups or could be easily modified to use for migrations. Download here.

 #Production Cluster Name   
 $ProdClustername = "PROD CLUSTER"  
 #DR Cluster Name  
 $DRClustername = "DR CLUSTER"  
 #DR Virtual Switch Name used to create new portgroups to  
 $DRVswitchName = "vSwitch0"  
 #Vlan id to be used at DR  
 $vlanid = 20  
 #Virtual Portgroup Suffix  
 $vportgroupSuffix = "DR-DHCP"  
 #Connect to production Vcenter  
 Connect-VIServer PRODVCENTER  
 #Get portgroups from production  
 $portgroups = get-cluster $ProdClustername | get-vmhost | Get-VirtualPortGroup  
 #Disconnect from Production VCenter  
 Disconnect-VIServer -Confirm $false  
 #Connect to DR vcenter  
 Connect-VIServer DRVCENTER  
 #Loop through the list of hosts at DR site  
 foreach ($vmhost in (get-cluster $DRClustername | Get-VMHost)){  
      $vswitch = $vmhost | Get-VirtualSwitch -name $DRVswitchName  
      #Add the portgroups to each host at DR site  
      foreach ($portname in $portgroups){  
      Write-Host "Adding Portgroup $portname-$vportgroupSuffix to DR"  
      New-VirtualPortGroup -Name "$portname-$vportgroupSuffix" -VirtualSwitch $vswitch -VLanId $vlanid   
 #Disconnect DR Vcenter  
 Disconnect-VIServer -confirm $false  

Thursday, August 1, 2013

SCSI Unmap Tool for ESXi5.0 / ESXi5.1

 Last night I was hit with a question from a client about performing SCSI unmaps on an equallogic array. At first I reviewed Cormac Hogan's excellent blog post on performing this operation here. After reviewing this process I was thinking it would be beneficial to have a GUI for this operation to make it easier for execution. So, last night I went to work on a long coding binge and came up with the first iteration of SCSI unmap tool v1.0 .
 I wouldn't say it was the prettiest interface in the world but it's functional. Designed to run from the top down. Some caveats is this process does create a file based on percentage of free space you would like to reclaim. It will cause added I/O to your array during operation so should be performed during maintenance windows.

NOTE: this feature was removed from esxi5.0 due to unmap duration causing snapshot consolidation and storage vmotion timeouts while it was executing.


  1. Powercli 5.1 or greater
  2. One LUN per datastore
  3. Execute during Maintenance window or low I/O times
  4. SSH is enabled on your esxi host performing the unmap operation
  5. v1.0 only supports using one esx host and one datastore per operation
  6. Requires root ssh access.

Tool Overview

For this test I will use a Equallogic Array with one thin provisioned volume. I created some temp vmdks on the volume and added files to the disk through the guest operating system. After completing this step I removed the vmdk from the datastore leaving freespace that is now avaliable in vsphere but showing consumed on my equallogic volumes. See screenshots:

VMFS Volume and EQ Volume before SCSI Unmap

Now I will open the GUI and execute the program to perform unmap operation.

 Below is a screenshot of the same EQ volume after the operation has completed. Due to low load on the EQ array this process took seconds after executing.

For right know the GUI only supports one esx host and one lun per operation. If you would like to do more luns at ones you will need to open multiple copies of the GUI. This was originally target for single lun use.

Download the script here