VMware Cloud Community
kirtyakshay
Contributor
Contributor
Jump to solution

Script to get VAAI Status

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

pastedImage_1.png

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

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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.

Get-VMHost |

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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

Get-VMHost |

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

0 Kudos
kirtyakshay
Contributor
Contributor
Jump to solution

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 :

pastedImage_1.png

If I execute the command ($device = $esxcli.storage.core.device.list()) separately on a host, I do see these values getting populated :

pastedImage_0.png

Akshay Kirty

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.

Get-VMHost |

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

0 Kudos
kirtyakshay
Contributor
Contributor
Jump to solution

Wonderful....Thank you so much for your help.

Akshay Kirty

0 Kudos