VMware Cloud Community
antoniogemelli
Hot Shot
Hot Shot

Get host Lun and device info

Hello,

I have this script where I can get a lot of information's and I would like to add host (to be easy to identify) for each row, is possible?

Adapter

AdapterIdentifier

AdapterTransportDetails

ChannelDevice

DeviceDisplayName

LUN

MaximumIOSize

Plugin

RuntimeName

State

Target

TargetIdentifier

TargetTransportDetails

Transport

UID

Host?

&{Get-VMhost | %{

         $esxcli = Get-esxcli -VMHost $_

         $esxcli.storage.core.path.list()

    }} | Export-Csv -path C:\Users\gemela\Desktop\SANLUN.csv

0 Kudos
2 Replies
mattboren
Expert
Expert

Hello, -

You can include the VMHost as a property of each object by adding a new calculated property to the output.  Like:

& {Get-VMHost -PipelineVariable oThisVMHost | Foreach-Object {

    $esxcli = Get-EsxCli -VMHost $_

    $esxcli.storage.core.path.list() | Select-Object -Property *, @{Name="VMHost"; e={$oThisVMHost}}

}} | Export-Csv -NoTypeInformation -Path C:\Users\gemela\Desktop\SANLUN.csv

How does that do for you?

0 Kudos
jooshilaig
Enthusiast
Enthusiast

Try this script , it will give you an CSV output

Header 1

$Usr="root"

$pwd='password'

$CSVFile = ".\HostList.csv"

$filelocation=".\MPath.csv"

$hosts=Import-CSV $CSVFile

foreach($singleViserver in $hosts)

{

$esxiserver=$singleViserver.name

Connect-VIServer $singleViserver.name -User $Usr -password $pwd | Out-Null

Write-Host "Getting the Multipath for Host $esxiserver......." -ForegroundColor Yellow

$esxcli = get-vmhost $singleViserver.name | Get-EsxCli

$esxcli.storage.core.path.list() |select @{N="VMHost";E={$ESXCLI.VMHost}},Adapter,AdapterIdentifier,AdapterTransportDetails,Channel,Device,DeviceDisplayName,LUN,Plugin,RuntimeName,State,Target,TargetIdentifier,TargetTransportDetails,Transport,UID|Export-Csv -Append $filelocation -Delimiter ","

}

0 Kudos