Hi All, (again )
I am trying to convert a cmdlet output after selecting a property and convert it to Jason.
The problem is that I get all the data but each value gets the key beside it.
I was expecting to have it grouped (in the jason format) so I get one property âAddressâ and all the values, instead I get âAddressâ duplicated.
Can someone help please?
PS C:\Users\xxx> Get-NcNetInterface | select Address
Address
-------
169.254.231.133
169.254.32.182
169.254.214.116
PS C:\Users\xxx> Get-NcNetInterface | select Address | ConvertTo-Json
[
{
"Address": "169.254.231.133"
},
{
"Address": "169.254.32.182"
},
{
"Address": "169.254.214.116"
}
]
Command without the convert:
PS C:\Users\xxx> Get-NcNetInterface | select Address
Address
-------
169.254.231.133
169.254.32.182
169.254.214.116
Its working as I would expect.
I donât have the ONTAP toolkit on my machine but using Get-NetIPAddress gives similar results
PS> Get-NetIPAddress -AddressFamily IPv4 | select IPAddress | ConvertTo-Json
[
{
âIPAddressâ: â127.0.0.1â
},
{
âIPAddressâ: â169.254.107.168â
},
{
âIPAddressâ: â169.254.76.205â
},
{
âIPAddressâ: â169.254.242.182â
},
{
âIPAddressâ: â10.10.54.200â
},
{
âIPAddressâ: â192.168.0.6â
}
]
Your command, and mine, produce a collection of objects. Each object is converted to JSON and added to the array of JSON objects.
So in your case the first object is converted to
{
âAddressâ: â169.254.231.133â
}
Hey Richard,
Thanks for the reply.
I understand the the convert is doing some sort of foreach for all the collection of objects.
But in PowerShell console I can see the objects grouped to a table, I would like to select the column I want and have it converted to jason but keep the same format so I get one âAddressâ field with all the values it has (IPs).
Can this be achieved?