Hi All,
I've been using this neat little script to identify host to LUN path policy and status, however was hoping someone could assist in modifying it to only list LUNS with an naa starting with naa.600500* and instead of listing the lunName list the Datastore name ?
$lunpathinfo = @()
foreach ($vmhost in get-cluster "CLUSTER" | get-vmhost) {
$hostview= get-view $vmhost.id
$hostview.config.storagedevice.multipathinfo.lun | % { `
$lunname=$_.id
$lunpolicy=$_.policy.policy
$_.path | % {
$pathstate=$_.pathstate
$lunpathinfo += "" | select @{name="Hostname"; expression={$vmhost.name}},
@{name="LunName"; expression={$lunname}},
@{name="LunPolicy"; expression={$lunpolicy}},
@{name="PathState"; expression={$pathstate}}
}
}
}
$lunpathinfo | export-csv c:host_luns.csv
Hello, nicholas1982-
You can additionally retrieve the CanonicalName of the LUNs, so as then be able filter on them. You could either do the filtering in the foreach script block, or, probably a more re-usable way, return the CanonicalName as a property, and then filter on it. So, like:
&{foreach ($vmhost in Get-Cluster "CLUSTER" | Get-VMHost) {
## the .Net View of this host, with just a select set of properties
$hostview = Get-View $vmhost.id -Property Config.Storagedevice.Multipathinfo.Lun,Config.Storagedevice.ScsiLun
$hostview.Config.Storagedevice.Multipathinfo.Lun | % {
## the Lun "key" of this HostMultipathInfoLogicalUnit, to be used to get the corresponding ScsiLun of the same Key, so as to get the CanonicalName of the LUN
$strThisMPInfoLun_LunKey = $_.Lun
$lunname=$_.Id
$lunpolicy=$_.Policy.Policy
$_.path | % {
New-Object -Type PSObject -Property @{
Hostname = $vmhost.Name
LunName = $lunname
LunPolicy = $lunpolicy
PathState = $_.Pathstate
## the CanonicalName of the ScsiLun that corresponds to this HostMultipathInfoLogicalUnit
LunCanonicalName = ($hostview.Config.Storagedevice.ScsiLun | ?{$_.Key -eq $strThisMPInfoLun_LunKey}).CanonicalName
} ## end new-object
}
}
}} | ?{$_.LunCanonicalName -like "naa.600500*"} | Export-Csv -NoTypeInformation -UseCulture c:\Temp\host_luns.csv
Along with the new property, I changed things a bit:
How does this goodness do for you?
Hello, nicholas1982-
You can additionally retrieve the CanonicalName of the LUNs, so as then be able filter on them. You could either do the filtering in the foreach script block, or, probably a more re-usable way, return the CanonicalName as a property, and then filter on it. So, like:
&{foreach ($vmhost in Get-Cluster "CLUSTER" | Get-VMHost) {
## the .Net View of this host, with just a select set of properties
$hostview = Get-View $vmhost.id -Property Config.Storagedevice.Multipathinfo.Lun,Config.Storagedevice.ScsiLun
$hostview.Config.Storagedevice.Multipathinfo.Lun | % {
## the Lun "key" of this HostMultipathInfoLogicalUnit, to be used to get the corresponding ScsiLun of the same Key, so as to get the CanonicalName of the LUN
$strThisMPInfoLun_LunKey = $_.Lun
$lunname=$_.Id
$lunpolicy=$_.Policy.Policy
$_.path | % {
New-Object -Type PSObject -Property @{
Hostname = $vmhost.Name
LunName = $lunname
LunPolicy = $lunpolicy
PathState = $_.Pathstate
## the CanonicalName of the ScsiLun that corresponds to this HostMultipathInfoLogicalUnit
LunCanonicalName = ($hostview.Config.Storagedevice.ScsiLun | ?{$_.Key -eq $strThisMPInfoLun_LunKey}).CanonicalName
} ## end new-object
}
}
}} | ?{$_.LunCanonicalName -like "naa.600500*"} | Export-Csv -NoTypeInformation -UseCulture c:\Temp\host_luns.csv
Along with the new property, I changed things a bit:
How does this goodness do for you?
Thanks Mattboren,
With the LunName I get a really long number, is there anyway to convert that to the vmware friendly datastore name?
Hello-
Sure there is (or, several ways, of course). One such way would be to get the View objects for the datastores in the given vCenter and use that array to "look up" the name of the datastore that uses the given LUN as an extent. I added in such things below, where just the first and last-few lines are adjusted:
## array of Views of datastores, to be used later for getting datastore name for given LUN canonical name
$arrDStoreViews = Get-View -ViewType Datastore -Property Name,Info
&{foreach ($vmhost in Get-Cluster "CLUSTER" | Get-VMHost) {
## the .Net View of this host, with just a select set of properties
$hostview = Get-View $vmhost.id -Property Config.Storagedevice.Multipathinfo.Lun,Config.Storagedevice.ScsiLun
$hostview.Config.Storagedevice.Multipathinfo.Lun | % {
## the Lun "key" of this HostMultipathInfoLogicalUnit, to be used to get the corresponding ScsiLun of the same Key, so as to get the CanonicalName of the LUN
$strThisMPInfoLun_LunKey = $_.Lun
$lunname=$_.Id
$lunpolicy=$_.Policy.Policy
$_.path | % {
New-Object -Type PSObject -Property @{
Hostname = $vmhost.Name
LunName = $lunname
LunPolicy = $lunpolicy
PathState = $_.Pathstate
## the CanonicalName of the ScsiLun that corresponds to this HostMultipathInfoLogicalUnit
LunCanonicalName = ($hostview.Config.Storagedevice.ScsiLun | ?{$_.Key -eq $strThisMPInfoLun_LunKey}).CanonicalName
} ## end new-object
}
}
}} | ?{$_.LunCanonicalName -like "naa.600c0ff000*"} |
Select-Object *,
@{n="DatastoreName"; e={$oThisObj = $_; ($arrDStoreViews | ?{$_.Info.Vmfs.Extent | ?{$_.DiskName -eq $oThisObj.LunCanonicalName}}).Name}} `
| Export-Csv -NoTypeInformation -UseCulture c:\Temp\host_luns.csv
This uses a calculated property to get the datastore name (if the given device is in use as an extent for a datastore). Work for you?
Hey Matt, That's awesome.. Are you able to remove the first column LunName ?
Hey Matt, All good I just commented that field, thanks for your help