Datastore to LUN Mapping (PowerCLI): Difference between revisions
Jump to navigation
Jump to search
(typo) |
(typo) |
||
Line 66: | Line 66: | ||
} | } | ||
} | } | ||
</ | </source> | ||
'''$objScsiLUN''' | '''$objScsiLUN''' |
Latest revision as of 09:51, 12 November 2010
During the running of the script below you come across a number of objects that all have potentially useful information, therefore to make adapting the script easier at a later date I've displayed example object displays.
Its also worth checking out the original VMware forum post for further info - http://communities.vmware.com/thread/240466#240466
# Thieved and adapted from the good work by catman...
# http://communities.vmware.com/thread/240466#240466
$objESX = Get-VMHost "My_ESX*"
# Get .NET views for host and storage system
$objViewESX = Get-View -id $objESX.id
$objViewESXstorageSys = Get-View -id $objViewESX.ConfigManager.StorageSystem
# Get FC HBAs
$HBAs = $objViewESXstorageSys.StorageDeviceInfo.HostBusAdapter | Where-Object {$_.Key -like "*FibreChannelHba*"}
#$HBAs
foreach ($hba in $HBAs) {
# Enumerate LUNs
$LUNcount = $objViewESXstorageSys.StorageDeviceInfo.MultiPathInfo.Lun.Length
#Write-Host ("Enumerating $LUNcount LUNs on " + $hba.Device)
for ($LUNidx = 0; $LUNidx -lt $LUNcount; $LUNidx++ ) {
$objScsiLUN = $objViewESXstorageSys.StorageDeviceInfo.MultiPathInfo.Lun[$LUNidx]
#$objScsiLUN
# Enumerate paths on LUN
$PathCount = $objScsiLUN.Path.Length
#Write-Host ("Enumerating $PathCount paths on " + $objScsiLUN.Id)
for ($PathIdx = 0; $PathIdx -lt $PathCount; $PathIdx++) {
$objSCSIpath = $objViewESXstorageSys.StorageDeviceInfo.MultiPathInfo.Lun[$LUNidx].Path[$PathIdx]
#Write-Host ($objSCSIpath.Name + " - " + $objSCSIpath.PathState)
# Only care about one path, active on current HBA
if (($objSCSIpath.PathState -eq "active") -and ($objSCSIpath.Adapter -eq $hba.Key)) {
# Now get the disk that we want
$objSCSIdisk = $objViewESXstorageSys.StorageDeviceInfo.ScsiLun | Where-Object{ ($_.CanonicalName -eq $objScsiLUN.Id) -and ($_.DeviceType -eq "disk") }
#$objSCSIdisk
# Now get the datastore info for disk
$MountCount = $objViewESXstorageSys.FileSystemVolumeInfo.MountInfo.Length
#Write-Host ("Enumerating $MountCount mounts on " + $objSCSIdisk.CanonicalName)
for ($MountIdx = 0; $MountIdx -lt $MountCount; $MountIdx++ ) {
if ($objViewESXstorageSys.FileSystemVolumeInfo.MountInfo[$MountIdx].Volume.Type -eq "VMFS" ) {
$objVolume = $objViewESXstorageSys.FileSystemVolumeInfo.MountInfo[$MountIdx].Volume
#$objVolume
$ExtentCount = $objVolume.Extent.Length
#Write-Host ("Enumerating $ExtentCount mounts on " + $objVolume.Name)
for ($ExtentIdx = 0; $ExtentIdx -lt $ExtentCount; $ExtentIdx++ ) {
$objExtent = $objVolume.Extent[$ExtentIdx]
# Match extent name to disk name
if ($objExtent.DiskName -eq $objSCSIdisk.CanonicalName) {
Write-Host($objSCSIdisk.Vendor + " " + $objSCSIdisk.Model + " " + $objSCSIdisk.CanonicalName + "`t" + $objVolume.Name)
}
}
}
}
}
}
}
}
$objScsiLUN
Key : key-vim.host.MultipathInfo.LogicalUnit-vmhba3:0:13 Id : vmhba3:0:13 Lun : key-vim.host.ScsiDisk-vmhba3:0:13 Path : {vmhba3:0:13, vmhba3:1:13, vmhba4:0:13, vmhba4:1:13} Policy : VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy StorageArrayTypePolicy : DynamicType : DynamicProperty :
$objSCSIdisk
Capacity : VMware.Vim.HostDiskDimensionsLba DevicePath : /vmfs/devices/disks/vml.02000d0000600508b40006b8e40000d00001280000485356323030 Key : key-vim.host.ScsiDisk-vmhba3:0:13 Uuid : 02000d0000600508b40006b8e40000d00001280000485356323030 Descriptor : CanonicalName : vmhba3:0:13 DisplayName : LunType : disk Vendor : HP Model : HSV200 Revision : 6110 ScsiLevel : 6 SerialNumber : unavailable DurableName : VMware.Vim.ScsiLunDurableName AlternateName : {4, 3, 5, 5} StandardInquiry : {0, 0, 5, 18...} QueueDepth : OperationalState : {ok} Capabilities : VStorageSupport : DeviceName : /vmfs/devices/disks/vml.02000d0000600508b40006b8e40000d00001280000485356323030 DeviceType : disk DynamicType : DynamicProperty :
$objVolume
BlockSizeMb : 1 MaxBlocks : 262144 MajorVersion : 3 Version : 3.31 Uuid : 48944e24-b5e93716-aa5c-001cc4466ba8 Extent : {vmhba3:0:8} VmfsUpgradable : False ForceMountedInfo : Type : VMFS Name : VMFSVol8 Capacity : 536602476544 DynamicType : DynamicProperty :