Hi,
we have two storage vendors, Pure and Nimble, Below script works for Pure, where I can get the Pure RDMs from a VM but I am unable to get Nimble RDM details of VM from Nimble RDMs.
Please help!!
Get-Cluster -PipelineVariable clus |
ForEach-Object -Process {
$rndNum = Get-Random -Maximum 99999
$LunInfoDef = @"
public string ClusterName;
public string Vendor;
public string CanonicalName;
public string UsedBy;
public string SizeGB;
public string DSC;
"@
$LunInfoDef = "public struct LunInfo" + $rndNum + "{`n" + $LunInfoDef
$esxServers = $clus | Get-VMHost | Sort-Object -Property Name
$esxServers | % {
$LunInfoDef += ("`n`tpublic string " + ($_.ExtensionData.config.Network.DnsConfig.Hostname) + ";")
}
$LunInfoDef += "`n}"
Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef
$scsiTab = @{ }
$esxServers | % {
$esxImpl = $_
# Get SCSI LUNs
$version = [Version]$esxImpl.Version
if ($version.Major -eq 6 -and $version.Minor -eq 0)
{
$esxImpl.ExtensionData.Config.StorageDevice.ScsiLun | Where-Object { $_.LunType -eq 'disk' } | % {
$key = $esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.DiskName.Split(".")[1]
$capacityGB = $_.Capacity.Block * $_.Capacity.BlockSize / 1GB
$lunUuid = $_.Uuid
$lun = $esxImpl.ExtensionData.Config.StorageDevice.MultipathInfo.Lun | Where-Object { $_.Id -eq $lunUuid }
$lunId = $lun.Path[0].Name.Split('L')[1]
$scsiTab[$key] = $_.CanonicalName, "", $capacityGB, $lunId, "", $_.Vendor
}
}
Else
{
$esxImpl | Get-ScsiLun | where { $_.LunType -eq "Disk" } | % {
$key = $esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.CanonicalName.Split(".")[1]
if (!$scsiTab.ContainsKey($key))
{
$lunId = $_.RuntimeName.Split('L')[1]
$scsiTab[$key] = $_.CanonicalName, "", $_.CapacityGB, $lunId, "", $_.Vendor
}
}
}
# Get the VMFS datastores
$esxImpl | Get-Datastore | Where-Object { $_.Type -eq "VMFS" } | Get-View | % {
$dsName = $_.Name
$dscName = ''
if ($_.Parent.Type -eq 'StoragePod')
{
$dscName = Get-View -Id $_.Parent -Property Name -Server $esxImpl.Uid.Split('@')[1].Split(':')[0] | Select -ExpandProperty Name
}
$_.Info.Vmfs.Extent | % {
$key = $esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.DiskName.Split(".")[1]
$scsiTab[$key][1] = $dsName
$scsiTab[$key][4] = $dscName
}
}
}
# Get the RDM disks
$clus | Get-VM | Get-View | % {
$vm = $_
$vm.Config.Hardware.Device | Where-Object { $_.gettype().Name -eq "VirtualDisk" } | % {
if ($_.Backing.PSObject.Properties['CompatibilityMode'] -and "physicalMode", "virtualMode" -contains $_.Backing.CompatibilityMode)
{
$disk = $_.Backing.LunUuid.Substring(10, 32)
$key = (Get-View $vm.Runtime.Host).config.Network.DnsConfig.Hostname + "-" + $disk
$scsiTab[$key][1] = $vm.Name + "/" + $_.DeviceInfo.Label
}
}
}
$scsiTab.GetEnumerator() | Group-Object -Property { $_.Key.Split("-")[1] } | % {
$lun = New-Object ("LunInfo" + $rndNum)
$lun.ClusterName = $clus
$_.Group | % {
$esxName = $_.Key.Split("-")[0]
$lun.$esxName = $_.Value[3]
if (!$lun.CanonicalName) { $lun.CanonicalName = $_.Value[0] }
if (!$lun.UsedBy) { $lun.UsedBy = $_.Value[1] }
if (!$lun.SizeGB) { $lun.SizeGB = [math]::Round($_.Value[2], 0) }
if (!$lun.Vendor) {$lun.Vendor = $_.Value[5]}
$lun.DSC = $_.Value[4]
}
$lun
} |
Export-Excel -Path $csvName -AutoFilter -AutoSize -WorksheetName $clus.name
}
I am getting few errors as below
Cannot index into a null array.
At D:\Free_LUNs_Info_2.0.ps1:93 char:17
+ ... $scsiTab[$key][1] = $vm.Name + "/" + $_.DeviceInfo.Label
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
I don't have access to that kind of HW.
I could have a look at the objects and the properties and try to discover why it doesn't work.
Try the following and show the results (and make sure it's showing a Nimble LUNs and an RDM on Nimble LUN).
Since I'm not sure how to filter for those Nimble LUNs, you will probably have to experiment a bit.
$esxImpl = Get-VMHost -Name 'anyESX'
$lun = $esxImpl.ExtensionData.Config.StorageDevice.ScsiLun | Where-Object { $_.LunType -eq 'disk' } |
Select -First 1
$pathLun = $esxImpl.ExtensionData.Config.StorageDevice.MultipathInfo.Lun | Where-Object { $_.Id -eq $lun.Uuid }
$lun | Format-Custom
$pathLun | Format-Custom
$rdm = Get-VM | Get-HardDisk -DiskType RawPhysical,RawVirtual | Select -First 1
$rdm.ExtensionData | Format-Custom
$rdm.EXtensionData.Backing | Format-Custom
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
One thing I forgot, does Get-ScsiLun return these Nimble LUNs?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes LucD,
yes, i can get Nimble and Pure disks using get-scsilun
Get-VMHost | Get-ScsiLun | Sort-Object VMhost | Select-Object VMHost, CanonicalName, CapacityGB, Vendor, MultipathPolicy, LunType, IsLocal, IsSsd,@{n='LunID';E={
$esxcli = Get-EsxCli -VMHost $_.VMHost-V2
$esxcli.storage.nmp.path.list.Invoke(@{'device'=$_.CanonicalName}).RuntimeName.Split(':')[-1].TrimStart('L')}}|
Sort-Object -Property {[int]$_.LUN}| ft -auto
I checked all the properties used in the script, and they all seem to be ok.
The only reason I can think of that could generate that error is that a VM, with an RDM, is not assigned to an ESXi node that is currently in the cluster, or the DNS name for that ESXi node is somehow incorrect.
Some debugging that might help.
Change the RDM section to this, and check what is displayed on the console just before the error message.
$clus | Get-VM | Get-View | % {
$vm = $_
$vm.Config.Hardware.Device | Where-Object { $_.gettype().Name -eq "VirtualDisk" } | % {
if ($_.Backing.PSObject.Properties['CompatibilityMode'] -and "physicalMode", "virtualMode" -contains $_.Backing.CompatibilityMode) {
$disk = $_.Backing.LunUuid.Substring(10, 32)
$key = (Get-View $vm.Runtime.Host).config.Network.DnsConfig.Hostname + "-" + $disk
Write-Host "ESXi : $($esxServers.Name -join '|')"
Write-Host "Hostname: $( (Get-View $vm.Runtime.Host).config.Network.DnsConfig.Hostname)"
Write-Host "VM: $($vm.Name) Key: $($key)"
Write-Host "Keys: $($scsiTab.Keys -join '|')"
$scsiTab[$key][1] = $vm.Name + "/" + $_.DeviceInfo.Label
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Hereby attached the output
I see the script has issue with gathering information from nimble RDMs. it is able to get the information of Nimble Datastores but not from RDMs (To which VM it is mapped to)
But the another script shows the Nimble RDM information
$DiskInfo = @()
foreach ($VMview in Get-VM bkp01 | Get-View) {
foreach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | Where-Object { $_.DeviceInfo.Label -match "SCSI Controller" })) {
foreach ($VirtualDiskDevice in ($VMView.Config.Hardware.Device | Where-Object { $_.ControllerKey -eq $VirtualSCSIController.Key })) {
$VirtualDisk = "" | Select-Object VMname, SCSIController, DiskName, SCSI_ID, DeviceName, DiskFile, DiskSize, Vendor
$VirtualDisk.VMname = $VMview.Name
$VirtualDisk.SCSIController = $VirtualSCSIController.DeviceInfo.Label
$VirtualDisk.DiskName = $VirtualDiskDevice.DeviceInfo.Label
$VirtualDisk.SCSI_ID = "$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)"
$VirtualDisk.DeviceName = $VirtualDiskDevice.Backing.DeviceName.Where{ $_ -ne '' } | ForEach-Object { $_.Substring(22, 24).ToUpper() }
$VirtualDisk.DiskFile = $VirtualDiskDevice.Backing.FileName
$VirtualDisk.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB / 1GB
$esxcli = Get-EsxCli -VMHost (Get-View -Id $VMview.Runtime.Host -Property Name).Name -V2
if ($VirtualDiskDevice.Backing.CompatibilityMode -in 'physicalMode','virtualmode'){
$devName = $VirtualDiskDevice.Backing.DeviceName
}
else{
$ds = Get-View -Id $VirtualDiskDevice.Backing.Datastore
$devName = $ds.Info.Vmfs.Extent[0].DiskName
}
$VirtualDisk.Vendor = $esxcli.storage.core.device.list.Invoke(@{device = $devName}).Vendor
$DiskInfo += $VirtualDisk
}
}
}
$DiskInfo | Sort-Object VMname, SCSI_ID | Format-Table -auto
That is, as far as I can tell, not an issue with Nimble LUNs, but due to the fact that some of your ESXi nodes have an IP address as their entry, not the FQDN.
That is a known issue with the script, check the comments in LUN report – datastore, RDM and node visibility
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
then why I am unable to get the used RDM details for Nimble RDMs in the report. But for Pure RDMs, I can see details.
No clue.
I would really need to check this in the actual environment.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
sure, request you to check and help me on this 🙂
What I meant, I need an environment with the actual HW to investigate.
Since I don't have that, I'm afraid I can't help any further.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Sorry to bother you again, when I checked the UID, between Pure and Nimble storage, it is different here, does this make any difference in the script ?
I used the below script to get the LUNUUID
Get-VM DB1 | Get-HardDisk |
where {"RawPhysical","RawVirtual" -contains $_.DiskType} |
Select @{N="VM";E={$_.Parent.Name}},
@{N="UUID";E={$_.ExtensionData.Backing.LunUuid}},
Datastore
The Pure storage naa.624a9370c3776b2dac9a4f490001af7f matches the UUID, hence we are able to get the output for RDMs in the script
Pure RDM Output
VM UUID
-- ---- ---------
db1 0200d90000624a9370c3776b2dac9a4f490001af7f466c61736841
db1 0200d40000624a9370c3776b2dac9a4f49000e11ee466c61736841
db1 0200da0000624a9370c3776b2dac9a4f49000e11ed466c61736841
db1 0200fa0000624a9370c3776b2dac9a4f49000110a5466c61736841
db1 0200e50000624a9370c3776b2dac9a4f49000110ed466c61736841
The nimble storage eui.ea39872ee1ffb0fa6c9ce900b2e3cbee is not matching the UUID, is that could be we are not getting the RDM details from the script ?
Nimble Storage Output
VM UUID Datastore
-- ---- ---------
bkp01 01001800006561333938373265653166666230666136633963653930306232653363626565536572766572
bkp01 01003100006534323130643239353436646437633036633963653930306232653363626565536572766572
bkp01 01003200003537393163613662653335306661616136633963653930306232653363626565536572766572
bkp01 01003700006361316462646437623730353737383836633963653930306232653363626565536572766572
That could be the case since the RDM section uses part of the UUID in the Key (starting position 10 and with a length of 32 characters).
It looks as if we need to use the VML (VMware Legacy) notation to uniquely identify LUNs.
That seems to work for NAA and EUI notation.
The script assumed that all LUNs are using an NAA identifier.
I would have to check if I can convert the code to work with the VML notation to generate the key in $scsiTab.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD, Any luck today ? Did you get a chance to check ? 🙂
No, was away today.
Will continue later
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD, Any Luck on this ? Did you get a chance to check ?
LucD, Any Luck on this ? Did you get a chance to check ? Please help!!!
No, at closer inspection this requires a complete rewrite of the code.
And for the moment I didn't find the time to do that yet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference