I have a json file that I'm trying to convert to csv using the converfrom-json command. I'm having trouble parsing one part of the array string into separate rows. Here's an example:
[
{
"GroupName": "A",
"GroupID": "G001",
"GroupMemberIds": [
"M001",
"M002",
"M003",
"M004"
]
},
{
"GroupName": "B",
"GroupID": "G002",
"GroupMemberIds": [
"M001",
"M004",
"M005",
"M006"
]
}
]
My desired output to csv is:
GroupName GroupID GroupMemberId
A G001 M001
A G001 M002
A G001 M003
A G001 M004
B G002 M001
B G002 M004
B G002 M005
B G002 M006
I started with the following and tried different iterations but haven't found a solution yet. any help is greatly appreciated.
$obj = Get-Content -Path "C:\Temp\File.json" | ConvertFrom-Json $obj | select groupname, groupid, memberid | export-CSV "C:\Temp\groupmembers.csv" -NoTypeInformation
here's a sample file: https://drive.google.com/file/d/18WErwuOlU-4068852hsb9S8n9Bs52ndu/view?usp=sharing