Hello
This is not related to a specific Vmware powershell cmdlet question , a generic question on export to csv
Here is what i see when i run a powershell cmd
Get-MachineGroup XXX|select name,filters|Format-Table
Name Filters
---- -------
XXX {Server1, Server2, Server3, Server4...}
As you can see the list is not complete
So i tried
Get-MachineGroup XXX|select name,filters |export-csv c:\list.csv
but now the list shows as below for the server name col
Filters |
ST.PSModule.Protect.MachineGroups.DiscoveryFilter[] |
Tried
Get-MachineGroup |select name, @{N="Objects";E={$_.Filters}}
Get-MachineGroup |select name, @{N="Objects";E={$_.ST.PSModule.Protect.MachineGroups.DiscoveryFilter}}
No luck as well.
Any suggestion Please , how can i export that array of list of servers
Thanks
You are correct, the Export-Csv can't handle arrays.
It then displays the type of the value.
Your solution is correct.
An alternative to transform an array into a singular value could be
@{N="Filters";E={$_.Filters -join '|'}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD once mentioned .. trying to do what he did..
The Export-Csv cmdlet can handle properties that are arrays or complex objects correctly.
A way around this is to convert the array to a single string.
The PowerShell export-csv command needs a distinct property name (fieldname) for each value. This is precisely where the PSObject comes in handy. It is able to store a series of values for the property names with the values. It can store a large number of unique property names and values per object.
Array(s) have implicit labels for each value.
Still doing google
tried below no luck
$box = Get-MachineGroup
[pscustomobject]@{
name = $box.name
List = ($box.filters |Out-String).Trim()
}
No luck with below too
Get-MachineGroup | Select ‘Name’,@{Names1=’Filters’;Expression={[string]::join(“;”, ($_.Filters))}}
What i so far think is , below code is good,
Get-MachineGroup | Select name, @{N="Filters";E={[string]::Join(",",$_.Filters)}}
Name | Filters |
---- | ------- |
My Machine | ST.PSModule.Protect.MachineGroups.DiscoveryFilter |
The reason it shows above is internal of this cmdlet .. is that correct ? or i am doing something wrong on array extraction
You are correct, the Export-Csv can't handle arrays.
It then displays the type of the value.
Your solution is correct.
An alternative to transform an array into a singular value could be
@{N="Filters";E={$_.Filters -join '|'}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference