Hello I'm trying to get a CSV file with some information about paths with this script:
$lunpathinfo = @()
$esxName = "My_HostName"
$vmhost = Get-VMHost -Name $esxName
$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 Q:\POWERCLI\Out.csv
I can see that "$hostview.config.storagedevice.multipathinfo.lun" shows information as:
Key : key-vim.host.MultipathInfo.LogicalUnit-02001a000060060
e800565540000006554000000b74f50454e2d56
Id : 02001a000060060e800565540000006554000000b74f50454e2d56
Lun : key-vim.host.ScsiDisk-02001a000060060e8005655400000065
54000000b74f50454e2d56
Path : {fc.20000090fa6a8950:10000090fa6a8950-fc.50060e8005655
461:50060e8005655461-naa.60060e80056554000000655400000
0b7, fc.20000090fa6a711e:10000090fa6a711e-fc.50060e800
5655470:50060e8005655470-naa.60060e8005655400000065540
00000b7}
Policy : VMware.Vim.HostMultipathInfoFixedLogicalUnitPolicy
StorageArrayTypePolicy : VMware.Vim.HostMultipathInfoLogicalUnitStorageArrayTyp
ePolicy
DynamicType :
DynamicProperty :
And I want to extract in CSV file the path information (fc.2000...) but I can't. Is it possible?
Thank you so much
Try like this
$lunpathinfo = @()
$esxName = "My_HostName"
$vmhost = Get-VMHost -Name $esxName
# $hostview= get-view $vmhost.id
$vmhost.ExtensionData.config.storagedevice.multipathinfo.lun | % { `
$lunname=$_.id
$lunpolicy=$_.policy.policy
$_.path | % {
$pathstate=$_.pathstate
$pathName = $_.Name
$lunpathinfo += "" | select @{name="Hostname"; expression={$vmhost.name}},
@{name="LunName"; expression={$lunname}},
@{name="LunPolicy"; expression={$lunpolicy}},
@{N="Path";E={$pathName}},
@{name="PathState"; expression={$pathstate}}
}
}
$lunpathinfo | export-csv Q:\POWERCLI\Out.csv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is the script:
$lunpathinfo = @()
$esxName = "My_HostName"
$vmhost = Get-VMHost -Name $esxName
$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 Q:\POWERCLI\Out.csv
Try like this
$lunpathinfo = @()
$esxName = "My_HostName"
$vmhost = Get-VMHost -Name $esxName
# $hostview= get-view $vmhost.id
$vmhost.ExtensionData.config.storagedevice.multipathinfo.lun | % { `
$lunname=$_.id
$lunpolicy=$_.policy.policy
$_.path | % {
$pathstate=$_.pathstate
$pathName = $_.Name
$lunpathinfo += "" | select @{name="Hostname"; expression={$vmhost.name}},
@{name="LunName"; expression={$lunname}},
@{name="LunPolicy"; expression={$lunpolicy}},
@{N="Path";E={$pathName}},
@{name="PathState"; expression={$pathstate}}
}
}
$lunpathinfo | export-csv Q:\POWERCLI\Out.csv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Do you mean this information in PathName ?
$lunpathinfo = @()
$esxName = "My_HostName"
$vmhost = Get-VMHost -Name $esxName
$hostview= get-view $vmhost.id
$hostview.config.storagedevice.multipathinfo.lun | % { `
$lunname=$_.id
$lunpolicy=$_.policy.policy
$_.path | % {
$path = $_.name
$pathstate=$_.pathstate
$lunpathinfo += "" | select @{name="Hostname"; expression={$vmhost.name}},
@{name="LunName"; expression={$lunname}},
@{name="LunPolicy"; expression={$lunpolicy}},
@{name="PathState"; expression={$pathstate}},
@{name="PathName"; expression={$path}}
}
}
$lunpathinfo| export-csv Q:\POWERCLI\Out.csv
Damn LucD posted a little bit faster :S
Great!
A mini-question aboit the results :smileygrin:
Then, with PathState information...
"fc.20000090fa6a8950:10000090fa6a8950-fc.50060e8005655461:50060e8005655461-naa.60060e800565540000006554000000b9"
...we can know three parameters, right? These:
fc.20000090fa6a8950:10000090fa6a8950 --> Adapter Name.
fc.50060e8005655461:50060e8005655461 --> Target Name.
naa.60060e800565540000006554000000b9 --> LUN Name.
Thank you.
That is correct
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I used your comment to extent the script with adapter/target/lun splitted. Not sure if you need it but could be handy sometime
Either remove or leave the full path name which is commented now
$lunpathinfo = @()
$esxName = "My_VMhost"
$vmhost = Get-VMHost -Name $esxName
$vmhost.ExtensionData.config.storagedevice.multipathinfo.lun | % { `
$lunname=$_.id
$lunpolicy=$_.policy.policy
$_.path | % {
$pathstate=$_.pathstate
$pathName = $_.Name
$lunpathinfo += "" | select @{name="Hostname"; expression={$vmhost.name}},
@{name="LunName"; expression={$lunname}},
@{name="LunPolicy"; expression={$lunpolicy}},
@{name="PathState"; expression={$pathstate}},
# @{N="Path";E={$pathName}},
@{N="Adapter Name";E={$pathName.Split("-")[0]}},
@{N="Target Name";E={$pathName.Split("-")[1]}},
@{N="LUN Name";E={$pathName.Split("-")[2]}}
}
}
$lunpathinfo
Mmm... Good idea, with split option. Then, more difficult still... using the last script, I'm trying an invention: Merge the last script with another script that gets Lun information, joining 1st script "LUN Name" column with next script "CanonicalName" column. Uaaaaa!!
$Report = @()
$esxhost = "My HOST"
$VMHost=Get-VMHost $esxhost
$record = Get-ScsiLun -VmHost $VMHost -LunType disk | select @{N="VMHost";E={$VMHost.Name}},CanonicalName,MultiPathPolicy,RunTimeName,LunType,CapacityMB,CapacityGB, Model,Vendor, IsLocal
if($record){
$Report += $record
}
if($Report){
$Report | Export-Csv $("q:\Powercli\"+$esxhost+".CSV") -NoTypeInformation -UseCulture
}
A simple result for this last script:
"VMHost";"CanonicalName";"MultipathPolicy";"RuntimeName";"LunType";"CapacityMB";"CapacityGB";"Model";"Vendor";"IsLocal"
"My HOST";"naa.600601600720240008f2fedb8fdae311";"Fixed";"vmhba1:C0:T0:L92";"disk";"136192";"133";"RAID 10";"DGC";"False"
Guess it will be a script that will take too long to execute...
Best regards!