VMware Cloud Community
SCharchouf
Hot Shot
Hot Shot

Get All disks details with ESXi name

Hi All, I'm using the below scrip^t to retreive disks details, I need assistance to collect also the ESXi name

&{Get-VMhost | %{

     $esxcli = Get-esxcli -VMHost $_

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

}} | Export-Csv -path ..\Get_Local_Disks.csv

with the above script I'm getting the below details

Adapter   

AdapterIdentifier

AdapterTransportDetails

Channel

Device

DeviceDisplayName

LUN

MaximumIOSize

Plugin

RuntimeName

State

Target

TargetIdentifier

TargetTransportDetails

Transport

UID

Thank you in advance for your assistance

14 Replies
jpsider
Expert
Expert

when you say 'ESXi name' do you mean the host name? and you just want that added as a column in the CSV?

Reply
0 Kudos
SCharchouf
Hot Shot
Hot Shot

yep, you are right, as I have 5 vcenters and need to retreive disks details

Reply
0 Kudos
jpsider
Expert
Expert

Give this a shot:

$hostlist = Get-VMHost

foreach ($vmhost in $hostlist){

    $vmhostname = $vmhost.name

    $esxcli = Get-esxcli -VMHost $vmhost

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

    $data | Add-Member NoteProperty ESXi $vmhostname

    $data | Export-Csv -path ..\Get_Local_Disks.csv


}

Reply
0 Kudos
SCharchouf
Hot Shot
Hot Shot

Thank you very much Smiley Happy

Reply
0 Kudos
SCharchouf
Hot Shot
Hot Shot

Just one question, previously I'm able to retreive local disk info for the ESXi, but now only external disks are showing

is that normal?

Reply
0 Kudos
jpsider
Expert
Expert

That is interesting. When I run the commands, I get Local disks including CD-Roms.

Adapter                 : vmhba0

AdapterIdentifier       : sas.54cd98f06cbad300

AdapterTransportDetails : 54cd98f06cbad300

Channel                 : 2

Device                  : naa.64cd98f06cbad3002598b5d746cc145f

DeviceDisplayName       : Local DELL Disk (naa.64cd98f06cbad3002598b5d746cc145f)

LUN                     : 0

MaximumIOSize           : 1048576

Plugin                  : NMP

RuntimeName             : vmhba0:C2:T0:L0

State                   : active

Target                  : 0

TargetIdentifier        : sas.6098b5d746cc145f

TargetTransportDetails  : 6098b5d746cc145f

Transport               : sas

UID                     : sas.54cd98f06cbad300-sas.6098b5d746cc145f-naa.64cd98f06cbad3002598b5d746cc145f

ESXi                    : XXX

Adapter                 : vmhba32

AdapterIdentifier       : usb.vmhba32

AdapterTransportDetails : Unavailable or path is unclaimed

Channel                 : 0

Device                  : mpx.vmhba32:C0:T0:L0

DeviceDisplayName       : Local USB CD-ROM (mpx.vmhba32:C0:T0:L0)

LUN                     : 0

MaximumIOSize           : 32768

Plugin                  : NMP

RuntimeName             : vmhba32:C0:T0:L0

State                   : active

Target                  : 0

TargetIdentifier        : usb.0:0

TargetTransportDetails  : Unavailable or path is unclaimed

Transport               : usb

UID                     : usb.vmhba32-usb.0:0-mpx.vmhba32:C0:T0:L0

ESXi                    : XXX

Reply
0 Kudos
SCharchouf
Hot Shot
Hot Shot

I confirm it's strange, I tested twice and same result, no local disk retreived...

Reply
0 Kudos
SCharchouf
Hot Shot
Hot Shot

what also strange is that it provide only 1 Host...

I'm connected to vCenter and i executed the script...

I'm testing with another vCenter and keep you posted

Reply
0 Kudos
jpsider
Expert
Expert

did you change the code I posted at all? if so, can you post what you have?

Reply
0 Kudos
SCharchouf
Hot Shot
Hot Shot

No change, copy/past Smiley Happy

Reply
0 Kudos
jpsider
Expert
Expert

Heh, forgot to -Append

$hostlist = Get-VMHost

foreach ($vmhost in $hostlist){

    $vmhostname = $vmhost.name

    $esxcli = Get-esxcli -VMHost $vmhost

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

    $data | Add-Member NoteProperty ESXi $vmhostname

    $data | Export-Csv -path ..\Get_Local_Disks.csv -Append


}

LucD
Leadership
Leadership

As an alternative

Get-EsxCli -VMHost (Get-VMHost) -V2 -PipelineVariable esxcli |

ForEach-Object -Process {

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

    Add-Member -MemberType NoteProperty -Name VMHost -Value $esxcli.VMHost.Name -PassThru

} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

SCharchouf
Hot Shot
Hot Shot

LucD really this alternative is a good one Smiley Happy

Thank you

Reply
0 Kudos
Narayanan_5245
Enthusiast
Enthusiast

Hi LuCD,

This is the report i am also looking but here the host is coming in the last column. Can we able to modify the columns as per the below order.

Host Name

Adapter

RuntimeName

Target

LUN

State

Device

Device Display Name

Regards

Narayanan.

Reply
0 Kudos