I had a requirement to produce a report of which of my NetApp LUNs were mapped to which of my 3 VMware vSphere clusters. Each cluster has its own Igroup on the NetApp filer: –
- Prod-Cluster
- Dev-Cluster
- UAT-Cluster
Some LUNs are mapped to more than one cluster.
Using PowerShell with the Data ONTap module installed I could get a list of LUNs with
Get-NaLun
I could then filter this to just the ones that are mapped with
Get-NaLun | Where {$_.Mapped}
I collected the results of the above command into an array named $MappedLUNs, i..e
$MappedLUNs = Get-NaLun | Where {$_.Mapped}
I then setup an object with the property names I wanted to report on, by using a trick I learned from Hal Rottenberg by piping “” to the select commandlet, i.e.
$LUNMap = “” | Select LUN, Prod-Cluster, Test-Cluster, UAT-Cluster
Then for each of the objects in the $MappedLUNs array I got the LUN path and then using Get-NaLUNMap I obtained the LUNID property where the Initiator Group Name equalled each of the Igroups I was interested in, i.e.
ForEach ($LUN in $MappedLUNs) {
$LUNMap.LUN = $lun.path
$LUNMap.Prod-Cluster = (Get-NaLUNMap $LUN | Where {$_.InitiatorGroupName -eq “Prod-Cluster”}).LUNID
$LUNMap.Test-Cluster = (Get-NaLUNMap $LUN | Where {$_.InitiatorGroupName -eq “Test-Cluster}).LUNID
$LUNMap.UAT-Cluster = (Get-NaLUNMap $LUN | Where {$_.InitiatorGroupName -eq “UAT-Cluster”}).LUNID
$LUNMap
}
I saved all of these commands into a script file named Get-LUNMap.ps1 and piped the output through Export-CSV to get the results into a CSV file which I could load up into Microsoft Excel to perform some formatting, sorting and analysis, i.e.
Get-LUNMap.ps1 | Export-CSV lunmap.csv