Using the EMC Cmdlets with PowerCLI

As you know from my previous post “EMC PowerShell Cmdlets – Where to start” I have started looking at the EMC PowerShell cmdlets, one thing I was keen to use them for was to find information on my VMware Datastores.

This information is already available if you have the EMC VSI Plugin installed as GUI based information but I wanted to be able to script against this info, pull various bits of information that I needed and output it into a Spread sheet.

Unfortunately the cmdlets as they stand do not allow you to take a VMware datastore and get the underlying LUN information straight out but what they do allow, with a bit of messing around, is the ability to link the information and pull back what we need, with a little work during my lunch break I managed to create a function to allow us to match the datastore objects with the EMC Lun information.

Wouldn’t it be cool if we had a single cmdlet or function we could pipe Get-Datastore or Get-SCSILun information straight into to retrieve the EMC Lun information  – well now we can !

With the following function we can take a VMware datastore and pull the information back about the LUN in one simple line of code:

image

Or we can pull back the information for all datastores:

Get-Datastore | Get-EMCInfo

Or we can pass the VMware SCSILuns for a particular host and retrieve the underlying LUN information:

image

Or we can grab bits of information from both VMware and the EMC Array and add them together to give us the outputted items we are interested in:

SNAGHTML1aa8ad5a

SNAGHTML1aaa690a

The code to add various parts from the datastores or SCSILun’s can be found below:

$SMISAddress = "192.168.0.122"
$SMISPort = 5988
$SMISUsername = "admin"
$SMISPassword = "#1Password"
$VC = "192.168.0.100"
$VCUser = "Alan"
$VCPassword = "[email protected]$$W0rd"

if (!(get-pssnapin -name VMware.VimAutomation.Core -erroraction silentlycontinue)) {
	add-pssnapin VMware.VimAutomation.Core
}

If (!(Get-Module | Where {$_.Name -eq "EMC.PSToolkit.SMIS"})) {
	Import-Module "C:\program files\EMC\EMC PowerShell Cmdlets X64\EMC.PSToolkit.SMIS.dll"
}

If ($connection -eq $null) {
	$pass = ConvertTo-SecureString $SMISPassword -AsPlainText -Force
	$credentials = new-object -typename System.Management.Automation.PSCredential $SMISUsername, $pass

	$connection = Connect-EssSMISProvider -SMISProviderAddress $SMISAddress -SMISProviderCredential $credentials -Port $SMISPort
	if($connection -eq $null)
	{
   		Disconnect-EssSMISProvider
   		Throw "Error: Cannot connect to the designated SMI-S Provider."
	}
}

Function Get-EMCInfo {
	Param (
		[parameter(valuefrompipeline = $true, mandatory = $true, HelpMessage = "Enter a Datastore or ScsiLUN entity")]
		$DiskObj
	)

	Process {
		$DiskObj | Foreach {
			Switch ($DiskObj.GetType().Name ) {
				"DatastoreImpl" {
					$FullID = ($DiskObj.ExtensionData.Info.Vmfs.Extent | Select DiskName).DiskName
				}
				"ScsiLunImpl" {
					$FullID = $DiskObj.CanonicalName
				}
			}
			If ($FullID) {
				$WWN = $FullID.Remove(0,4)
				Get-EssStorageVolumes | Where {$_.EMCWWN -eq $WWN} | Select -First 1
			}
		}
	}
}

connect-viserver $VC -User $VCUser -Password $VCPassword

$DSLunReport = @()
Get-Datastore | ForEach-Object {
	$Info = New-Object PSObject
	$Info | add-member -membertype noteproperty -Name DSName -Value $_.Name
	$Info | add-member -membertype noteproperty -Name DSCapacityMB -Value $_.CapacityMB
	$Info | add-member -membertype noteproperty -Name DSFreeSpaceMB -Value $_.FreeSpaceMB
	$EMCLun = Get-EMCInfo $_
	$Info | add-member -membertype noteproperty -Name LUNName -Value $EMCLun.ElementName
	$Info | add-member -membertype noteproperty -Name LUNID -Value $EMCLun.ID
	$Info | add-member -membertype noteproperty -Name WWN -Value $EMCLun.EMCWWN
	$Info | add-member -membertype noteproperty -Name Type -Value ($EMCLun | Select -ExpandProperty Properties | Where {$_.Name -eq "Caption"}).Value
	$Info | add-member -membertype noteproperty -Name SPCurrentOwner -Value ($EMCLun | Select -ExpandProperty Properties | Where {$_.Name -eq "EMCCurrentOwningStorageProcessor"}).Value
	$Info | add-member -membertype noteproperty -Name SPDefaultOwner -Value ($EMCLun | Select -ExpandProperty Properties | Where {$_.Name -eq "EMCDefaultOwningStorageProcessor"}).Value
	$Info | add-member -membertype noteproperty -Name EMCThin -Value ($EMCLun | Select -ExpandProperty Properties | Where {$_.Name -eq "ThinlyProvisioned"}).Value
	$DSLunReport += $Info
}
$DSLunReport | Sort LUNID | Out-GridView

$SCSILunReport = @()
Get-VMHost | Select -first 1 | Get-ScsiLun | ForEach-Object {
	$Info = New-Object PSObject
	$Info | add-member -membertype noteproperty -Name CanonicalName -Value $_.CanonicalName
	$Info | add-member -membertype noteproperty -Name LunType -Value $_.LunType
	$Info | add-member -membertype noteproperty -Name CapacityMB -Value $_.CapacityMB
	$Info | add-member -membertype noteproperty -Name MultipathPolicy -Value $_.MultipathPolicy
	$EMCLun = Get-EMCInfo $_
	$Info | add-member -membertype noteproperty -Name LUNName -Value $EMCLun.ElementName
	$Info | add-member -membertype noteproperty -Name LUNID -Value $EMCLun.ID
	$Info | add-member -membertype noteproperty -Name WWN -Value $EMCLun.EMCWWN
	$Info | add-member -membertype noteproperty -Name Type -Value ($EMCLun | Select -ExpandProperty Properties | Where {$_.Name -eq "Caption"}).Value
	$Info | add-member -membertype noteproperty -Name SPCurrentOwner -Value ($EMCLun | Select -ExpandProperty Properties | Where {$_.Name -eq "EMCCurrentOwningStorageProcessor"}).Value
	$Info | add-member -membertype noteproperty -Name SPDefaultOwner -Value ($EMCLun | Select -ExpandProperty Properties | Where {$_.Name -eq "EMCDefaultOwningStorageProcessor"}).Value
	$Info | add-member -membertype noteproperty -Name EMCThin -Value ($EMCLun | Select -ExpandProperty Properties | Where {$_.Name -eq "ThinlyProvisioned"}).Value
	$SCSILunReport += $Info
}
$SCSILunReport | Sort LUNID | Out-GridView

4 thoughts on “Using the EMC Cmdlets with PowerCLI”

  1. Greetings sir

    Regarding the above. This is exactly what I am looking for to resolve a datastore rename issue I have at the moment. It would appear that the “EMC powershell cmdlets” as they were in this post no longer exist. EMC has moved them into EMC Storage Integrator but for example “Connect-EssSMISProvider” no longer seems to exist.

    You haven’t by any chance used the new set of cmdlets that come with ESI at all have you?

    Thank you very much!

  2. I am trying to get some HTML reporting on the VNX that can be ran by a bat file on a server (have this currently working for Active Directory and VMware).

    The problem with the Get-EmcStorageSystemCredential | Connect-EmcSystem command at the start is that it prompts for username, password.,, friendly name, spa a and b. Is there anyway to automatically feed this information in?

    Thanks in advance

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.