0

I am trying to export an array of multi-value properties to a CSV file but I am getting only a series of semi-columns using the following PowerShell code.


$machines | computerDnsName, @{name="ipAddresses";expression={$_.ipAddresses -join ";"}} | Export-Csv filename.csv  -NoTypeInformation

This PowerShell code works with single multi-valued property such as an email address (i.e., multiple email addresses for a user). However, it doesn't work for the multi-value field that contains another multi-value field such as listed below.

The multi-value properties that I am trying to extract and write to CSV file look like the following

IpAddresses:            {@{ipAddress=192.168.100.234; macAddress=B8EE65E45DCF; type=Other; operationalStatus=Up}, @{ipAddress=fe80::2f7a:3d3:7e2b:15f1; macAddress=B8EE65E45DCF; type=Other; 
                        operationalStatus=Up}, @{ipAddress=127.0.0.1; macAddress=000000000000; type=Other; operationalStatus=Up}, @{ipAddress=::1; macAddress=000000000000; type=Other; 
                        operationalStatus=Up}}

How can I extract these fields to CSV?

Thank you in advance

Planet-9
  • 37
  • 5
  • 1
    Please share with a us a https://stackoverflow.com/help/minimal-reproducible-example – Santiago Squarzon Aug 10 '21 at 01:14
  • What do you expect as an output? Knowing that you can't have multiple colums with the same name (objects with the same property names) in PowerShell. – iRon Aug 10 '21 at 06:11
  • @Santiago Squarzon - I extract the machine properties from Azure into **$machines** variable without any problem. When I export the content of **$machines** to the CSV file, everything works except where there is a multi-value field that contains another multi-value field such as listed in my question above. I am looking for help on how to process the inner multi-value fields. – Planet-9 Aug 10 '21 at 15:30
  • @iRon I would like to have a separate column for each network interface. For example: **IPaddress1**, **macAddress1**, **type1**, **OpsStatus1**, IPaddress2, macAddress2, type2, OpsStatus2, etc. However, I don't know how to process the inner multi-value fields. – Planet-9 Aug 10 '21 at 15:44
  • Does this answer your question? [Convert nested JSON array into separate columns in CSV file](https://stackoverflow.com/a/46081131/1701026) – iRon Aug 11 '21 at 07:00

0 Answers0