Hi,
I want to execute the below commands on all hosts in a vCenter and export the output to an excel.
$esxcli = Get-EsxCli -VMhost $esx
$vaai = $esxcli.storage.core.device.vaai.status.get()
$device = $esxcli.storage.core.device.list()
I want to get all the members of these 2 commands in the excel
I have been trying to write the script, but for most of the parameters, I get the output as "System.Object[]" even though there is a value for that.
Can anyone please help ?
Regards,
Akshay Kirty
That's because these properties are themselves arrays.
With a -join operator you can flatten an array to a string.
Something like this for example.
The Select-Object removes the 'array' properties and adds new calculated properties where these arrays are converted to a single string.
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMhost $_ -V2
$esxcli.storage.core.device.list.Invoke() |
Select -ExcludeProperty AttachedFilters,OtherUids,SupportedGuardTypes -Property *,
@{N='AttachFilters';E={$_.AttachedFilters -join '|'}},
@{N='OtherUids';E={$_.OtherUids -join '|'}},
@{N='SupportedGuardTypes';E={$_.SupportedGuardTypes -join '|'}} |
ForEach-Object -Process {
$row = $_
$esxcli.storage.core.device.vaai.status.get.Invoke(@{device=$row.Device}) |
ForEach-Object -Process {
$row | Add-Member -Name VAAIPluginName -Value $_.VAAIPluginName -MemberType NoteProperty -PassThru |
Add-Member -Name ATSStatus -Value $_.ATSStatus -MemberType NoteProperty -PassThru |
Add-Member -Name CloneStatus -Value $_.CloneStatus -MemberType NoteProperty -PassThru |
Add-Member -Name DeleteStatus -Value $_.DeleteStatus -MemberType NoteProperty -PassThru |
Add-Member -Name ZeroStatus -Value $_.ZeroStatus -MemberType NoteProperty -PassThru
}
}
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The indication System.Object[] is the way Export-Csv indicates that you are trying to store an array into a column.
To get single values, you have to use some nested forach loops.
Something like this for example
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMhost $_ -V2
$esxcli.storage.core.device.list.Invoke() |
ForEach-Object -Process {
$row = $_
$esxcli.storage.core.device.vaai.status.get.Invoke(@{device=$row.Device}) |
ForEach-Object -Process {
$row | Add-Member -Name VAAIPluginName -Value $_.VAAIPluginName -MemberType NoteProperty -PassThru |
Add-Member -Name ATSStatus -Value $_.ATSStatus -MemberType NoteProperty -PassThru |
Add-Member -Name CloneStatus -Value $_.CloneStatus -MemberType NoteProperty -PassThru |
Add-Member -Name DeleteStatus -Value $_.DeleteStatus -MemberType NoteProperty -PassThru |
Add-Member -Name ZeroStatus -Value $_.ZeroStatus -MemberType NoteProperty -PassThru
}
}
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This worked. I added the ESXi host name also.
However, I am just wondering that why only the below 3 columns still shows as "System.Object[]". Earlier all the columns showed this but now its just these 3 columns :
If I execute the command ($device = $esxcli.storage.core.device.list()) separately on a host, I do see these values getting populated :
Akshay Kirty
That's because these properties are themselves arrays.
With a -join operator you can flatten an array to a string.
Something like this for example.
The Select-Object removes the 'array' properties and adds new calculated properties where these arrays are converted to a single string.
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMhost $_ -V2
$esxcli.storage.core.device.list.Invoke() |
Select -ExcludeProperty AttachedFilters,OtherUids,SupportedGuardTypes -Property *,
@{N='AttachFilters';E={$_.AttachedFilters -join '|'}},
@{N='OtherUids';E={$_.OtherUids -join '|'}},
@{N='SupportedGuardTypes';E={$_.SupportedGuardTypes -join '|'}} |
ForEach-Object -Process {
$row = $_
$esxcli.storage.core.device.vaai.status.get.Invoke(@{device=$row.Device}) |
ForEach-Object -Process {
$row | Add-Member -Name VAAIPluginName -Value $_.VAAIPluginName -MemberType NoteProperty -PassThru |
Add-Member -Name ATSStatus -Value $_.ATSStatus -MemberType NoteProperty -PassThru |
Add-Member -Name CloneStatus -Value $_.CloneStatus -MemberType NoteProperty -PassThru |
Add-Member -Name DeleteStatus -Value $_.DeleteStatus -MemberType NoteProperty -PassThru |
Add-Member -Name ZeroStatus -Value $_.ZeroStatus -MemberType NoteProperty -PassThru
}
}
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Wonderful....Thank you so much for your help.
Akshay Kirty