VMware Cloud Community
DevKhurana
Enthusiast
Enthusiast
Jump to solution

Need to get all esxi host storage device details in CSV file

Hello guys, Could any one help me getting my all hosts storage details of vcenter in one CSV file. I am running this below written script but it is giving me only one host details. I know I am doing something wrong in this script.

 

 

$VMhosts = Get-VMHost -PipelineVariable esxihost

ForEach ($VMhost in $VMhosts) {

$esxcli = get-vmhost $VMhost | Get-EsxCli

$esxcli.storage.core.device.list() | Select @{N='VMHost';E={$VMhost.Name}}, DevfsPath,
Device, DeviceMaxQueueDepth,
DeviceType, DisplayName, DriveType, EmulatedDIXDIFEnabled, HasSettableDisplayName, IsBootDevice,
IsBootUSBDevice, IsLocal, IsLocalSASDevice, IsOffline, IsPerenniallyReserved, IsPseudo, IsRDMCapable,
IsRemovable, IsSAS, IsSSD, IsSharedClusterwide, IsUSB, IsVVOLPE, Model,MultipathPlugin,
NoofoutstandingIOswithcompetingworlds,NumberofPhysicalDrives,OtherUIDs,PIActivated,PIProtectionMask,
PIType,ProtectionEnabled,QueueFullSampleSize,QueueFullThreshold, RAIDLevel, Revision, SCSILevel,
Size,Status,SupportedGuardTypes,ThinProvisioningStatus,VAAIStatus,Vendor| Export-Csv -Path E:\devices.csv -NoTypeInformation -UseCulture }

0 Kudos
1 Solution

Accepted Solutions
fabio1975
Commander
Commander
Jump to solution

Ciao 

try your script with changes highlighted in bold:

$VMhosts = Get-VMHost -PipelineVariable esxihost

$value = ForEach ($VMhost in $VMhosts) {

$esxcli = get-vmhost $VMhost | Get-EsxCli

$esxcli.storage.core.device.list() | Select @{N='VMHost';E={$VMhost.Name}}, DevfsPath,
Device, DeviceMaxQueueDepth,
DeviceType, DisplayName, DriveType, EmulatedDIXDIFEnabled, HasSettableDisplayName, IsBootDevice,
IsBootUSBDevice, IsLocal, IsLocalSASDevice, IsOffline, IsPerenniallyReserved, IsPseudo, IsRDMCapable,
IsRemovable, IsSAS, IsSSD, IsSharedClusterwide, IsUSB, IsVVOLPE, Model,MultipathPlugin,
NoofoutstandingIOswithcompetingworlds,NumberofPhysicalDrives,OtherUIDs,PIActivated,PIProtectionMask,
PIType,ProtectionEnabled,QueueFullSampleSize,QueueFullThreshold, RAIDLevel, Revision, SCSILevel,
Size,Status,SupportedGuardTypes,ThinProvisioningStatus,VAAIStatus,Vendor}

$value | export-csv -NoTypeInformation -path e:\ListStorage.csv
Fabio

Visit vmvirtual.blog
If you're satisfied give me a kudos

View solution in original post

3 Replies
fabio1975
Commander
Commander
Jump to solution

Ciao 

try your script with changes highlighted in bold:

$VMhosts = Get-VMHost -PipelineVariable esxihost

$value = ForEach ($VMhost in $VMhosts) {

$esxcli = get-vmhost $VMhost | Get-EsxCli

$esxcli.storage.core.device.list() | Select @{N='VMHost';E={$VMhost.Name}}, DevfsPath,
Device, DeviceMaxQueueDepth,
DeviceType, DisplayName, DriveType, EmulatedDIXDIFEnabled, HasSettableDisplayName, IsBootDevice,
IsBootUSBDevice, IsLocal, IsLocalSASDevice, IsOffline, IsPerenniallyReserved, IsPseudo, IsRDMCapable,
IsRemovable, IsSAS, IsSSD, IsSharedClusterwide, IsUSB, IsVVOLPE, Model,MultipathPlugin,
NoofoutstandingIOswithcompetingworlds,NumberofPhysicalDrives,OtherUIDs,PIActivated,PIProtectionMask,
PIType,ProtectionEnabled,QueueFullSampleSize,QueueFullThreshold, RAIDLevel, Revision, SCSILevel,
Size,Status,SupportedGuardTypes,ThinProvisioningStatus,VAAIStatus,Vendor}

$value | export-csv -NoTypeInformation -path e:\ListStorage.csv
Fabio

Visit vmvirtual.blog
If you're satisfied give me a kudos

LucD
Leadership
Leadership
Jump to solution

You have the EXport-Csv inside the foreach loop, hence the CSV is overwritten each time (no -Append switch).
And you only see the last VMHost object from the loop.

Also the foreach statement does not place anything in the pipeline, while the Foreach-Object cmdlet does.

Get-VMHost -PipelineVariable esxihost
Foreach-Object -Process {
  $esxcli = Get-EsxCli -VMHost $esxihost -V2
  
  $esxcli.storage.core.device.list.Invoke() | 
  Select @{N='VMHost';E={$VMhost.Name}}, DevfsPath,
    Device, DeviceMaxQueueDepth,
    DeviceType, DisplayName, DriveType, EmulatedDIXDIFEnabled, HasSettableDisplayName, IsBootDevice,
    IsBootUSBDevice, IsLocal, IsLocalSASDevice, IsOffline, IsPerenniallyReserved, IsPseudo, IsRDMCapable,
    IsRemovable, IsSAS, IsSSD, IsSharedClusterwide, IsUSB, IsVVOLPE, Model,MultipathPlugin,
    NoofoutstandingIOswithcompetingworlds,NumberofPhysicalDrives,OtherUIDs,PIActivated,PIProtectionMask,
    PIType,ProtectionEnabled,QueueFullSampleSize,QueueFullThreshold, RAIDLevel, Revision, SCSILevel,
    Size,Status,SupportedGuardTypes,ThinProvisioningStatus,VAAIStatus,Vendor
} | 
Export-Csv -Path E:\devices.csv -NoTypeInformation -UseCulture


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

0 Kudos
DevKhurana
Enthusiast
Enthusiast
Jump to solution

Thanks @fabio1975  for helping me

 

 

 

0 Kudos