Does anyone have a script that will export all ESXi storage WWN, devices, number of paths and path state?
I want to use it for an upcoming code upgrade on our storage array.
Have you searched in this community?
What do you already have?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc, This is the code I started grooming for my environment. I got all the errors out but the script runs for a long time, I let it run for hours with no response output.
I also looked at https://www.lucd.info/2011/11/14/storage-views-datastores/ but I was unsure how to get it to pull from the entire vSphere as there are multiple datacenters in each.
What I am looking for is the script to cycle through all ESXi hosts in vSphere, and report back the HBA device paths with status for an upcoming code upgrade on the storage array.
connnect-VIServer -Server 'myvc'
Check if this is faster
Connect-VIServer -Server 'myvc'
Get-Content -Path 'C:\host list.txt' -PipelineVariable line |
ForEach-Object -Process {
$esx = Get-VMHost -Name $line
$stor = Get-View -Id $esx.ExtensionData.ConfigManager.StorageSystem
$stor.StorageDeviceInfo.ScsiLun | where{$_.DeviceType -eq 'disk'} |
ForEach-Object -Process {
$lun = $_
$paths = $stor.StorageDeviceInfo.MultipathInfo.Lun | where{$_.Lun -eq $lun.Key}
if($lun.CanonicalName -eq 'naa.6000c299d9d27e16d33d744a4f2446b8'){
$LUN.CanonicalName
}
$ds = $stor.FileSystemVolumeInfo.MountInfo | where{$_.Volume.Extent.DiskName -contains $lun.CanonicalName}
New-Object -TypeName PSObject -Property ([ordered]@{
VMHost = $esx.Name
HBA = $stor.StorageDeviceInfo.MultipathInfo.lun.Policy.Prefer.Split(':')[0] -join '|'
CanonicalName = $lun.CanonicalName
MultiPathPolicy = $paths.Policy.Policy -join '|'
LUNPathCount = $paths.Count
Datastore = $ds.Volume.Name
DSType = $ds.Volume.Type
})
}
} | Export-Csv -Path 'NJESXPATHS.csv' -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc, Here is the error that comes up.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\Users\bgonzales-a\Documents\scripts\DSPathInfo-v2.ps1:15 char:9
+ New-Object -TypeName PSObject -Property ([ordered]@{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\Users\bgonzales-a\Documents\scripts\DSPathInfo-v2.ps1:15 char:9
+ New-Object -TypeName PSObject -Property ([ordered]@{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\Users\bgonzales-a\Documents\scripts\DSPathInfo-v2.ps1:15 char:9
+ New-Object -TypeName PSObject -Property ([ordered]@{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I had a type in the HBA property.
I corrected the code above.
But I'm not sure why you would have a $null entry in there.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
HI Luc, not sure I follow.. Can you paste the code please?
I corrected the code I posted earlier inline.
Just do a new copy/paste
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference