NAA ID To VMAX Device ID – using powershell

A few months ago I noticed a link to this awesome article titled: NAA id’s and breaking them apart, which dissects the NAA identifiers that you see in the vSphere client when looking at storage devices. Recently I was working with my storage admin — I was seeing a 2.81MB device on all of the hosts in a cluster that he had not specifically presented. Unfortunately I had no good way to tell him exactly which device I was seeing. I then remembered and found this article and was able to convert the NAA ID to the VMAX device ID using the key described in the article. While converting this device ID by hand, I thought…wouldn’t it be nice if I could just paste in the NAA ID and automatically convert it to the device ID? I threw together a quick powershell function that does just that:

[cc lang=”powershell”]
Function Convert-NaaIdToVmaxDeviceId ($naa) {
# http://vmwise.com/2012/06/01/naa-ids-and-breaking-them-apart/
if ($naa.length -ne 36) { “NAA value must be 36 characters”; break }
$deviceString = $naa.ToCharArray()
$device = [char][Convert]::ToInt32(“$($deviceString[26])$($deviceString[27])”, 16)
$device += [char][Convert]::ToInt32(“$($deviceString[28])$($deviceString[29])”, 16)
$device += [char][Convert]::ToInt32(“$($deviceString[30])$($deviceString[31])”, 16)
$device += [char][Convert]::ToInt32(“$($deviceString[32])$($deviceString[33])”, 16)
$device += [char][Convert]::ToInt32(“$($deviceString[34])$($deviceString[35])”, 16)
return $device
}
[/cc]

The function expects just one parameter and can be used like this:

Convert-NaaIdToVmaxDeviceId "naa.60000970000000000000533031363641"
Posted in Scripting, Virtualization | 9 Comments

Detaching SCSI LUNs from ESXi hosts

About a month ago I experienced a production outage that related to improper removal of storage from a cluster. In this scenario, VMFS file systems were deleted from FC devices and then the FC devices were removed from the hosts. I’ve seen this done hundreds of times without issue, but as a best practice the devices should be detached from the host before they are removed. Here are some articles that discuss proper removal:

Manually detaching devices from a bunch of hosts doesn’t sound like a fun to me, so I created a quick script to help:
[cc lang=”powershell”]
#These are the temporary LUNs
$removeThese = @()
Get-Datastore *Temp |%{
$removeThese += $_.ExtensionData.info.Vmfs.Extent[0].diskName
}

#Manually delete file systems, then run the following:

Get-VMHost esxi0* | %{
$vmHost = $_
$vmHost.name
$removeThese | %{
$esxcli = Get-EsxCli -VMHost $vmHost
$esxcli.storage.core.device.set(“$_”,$null,$null,”off”)
}#end device loop
}#end host loop
[/cc]
Note: This code only works with ESXi 5.0 or later. I recently tested on an ESXi 4.1 host and this code does not work. (In 4.1 Get-EsxCli doesn’t have a storage.core namespace)

Posted in Scripting, Virtualization | Leave a comment

Create Win32_Process

When I first started with powershell, I converted some functions from a VBscript template I used into powershell code. One of those functions used WMI to create a process on a remote machine and then return the process ID that was created. The function is included at the end of this post.

Last week I worked with a colleague who was using a slightly modified version of this function. It was working fine for most processes, but in one particular case the process was failing on the remote Windows 2003 machine with an out of memory exception. If someone logged into the remote box and ran the process locally it would work fine. The function doesn’t define anything special about memory limits, so I started looking into the win32_process to see if there were memory limits that could be configured. Fortunately I was able to find this article http://blogs.technet.com/b/askperf/archive/2008/09/16/memory-and-handle-quotas-in-the-wmi-provider-service.aspx that discusses this specific issue. We ended up chaing the MemoryPerHost value from 134217728 (128MB) to 1073741824 (1024MB) and the process was able to complete.

[cc lang=”powershell”]
Function Start-WmiProcess ($computer, $cmd) {
$scope = New-Object management.managementscope “\\$computer\root\cimv2”
$scope.Connect()
$mp = new-object management.managementpath “win32_process”
$ogo = new-object management.objectgetoptions
$proc = new-object management.managementclass $scope,$mp,$ogo
$procID = ($proc.Create($cmd)).ProcessID
return $procID
}
[/cc]

Posted in Scripting | Leave a comment

Using vSphere Image Builder and Powerpath/VE

I typically use vSphere Image Builder to create custom ISO images that contain EMC PowerPath VE. The problem is, I need to add three packages in the correct order — and I never can remember the correct order. A few tries and I usually have what I need. I thought it would be worthwhile to write these down, so at the very least I could find the correct order in the future.

The code below assumes you have the ESXi500-201206001.zip and EMCPower.VMWARE.5.7.P01.b002.zip folders already downloaded and stored in your current working directory.

[cc lang=”Powershell”]
$buildName = “VM50-721882_ppve57p1”

Add-EsxSoftwareDepot –DepotUrl ESXi500-201206001.zip
$standard = Get-EsxImageProfile | ?{$_.Name -match ‘standard’}
$newProfile = New-EsxImageProfile -CloneProfile $standard.name -Name $buildName

# Add powerpath VE to the image
Add-EsxSoftwareDepot -DepotUrl EMCPower.VMWARE.5.7.P01.b002.zip
“powerpath.lib.esx”,”powerpath.cim.esx”,”powerpath.plugin.esx” | %{ Add-EsxSoftwarePackage -ImageProfile $newProfile -SoftwarePackage $_ }

# Export Image in ISO and ZIP format
Export-EsxImageProfile –ImageProfile $newProfile -FilePath “$buildName.iso” -ExportToIso
Export-EsxImageProfile –ImageProfile $newProfile -FilePath “Bundle_$buildName.zip” -ExportToBundle
[/cc]

Posted in Scripting, Virtualization | Leave a comment

VMworld 2012 – Powershell dinner

My favorite part of VMworld is the people you meet. Last week I was lucky enough to meet up with many powershell/PowerCLI experts and have some awesome discussions.


I wasn’t able to get everyones name/card, but I believe the first person in that picture is from Cisco, followed by Matt Boren (@mtboren), Eric Williams (@aeroic78), Dimitar Hristov, Alan Renouf (@alanrenouf), Hal Rottenberg (@halr9000), Luc Dekens (@LucD22), Josh Atwell (@Josh_Atwell), Brian Wuchner (@bwuch), Jonathan Medd (@jonathanmedd), Allen Crawford (@allen_crawford) and Clinton Kitson (@clintonskitson)

Posted in Scripting, Virtualization | 1 Comment