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 }
Ciao
try your script with changes highlighted in bold:
Ciao
try your script with changes highlighted in bold:
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