Reputation: 1583
This is my PowerShell which is calling an API and returning a JSON response.
$output = Get-SurveyParticipents `
-url "https://orxsurveys.limequery.com/admin/remotecontrol" `
-session $sessionKey `
-id "519965" `
-start "0" `
-limit "2" `
-unused $False `
-attributes ["completed", "usesleft"]
($output | Export-Csv -NoTypeInformation ./testtt.csv)
Write-host $output produces:
@{tid=6; token=35ddmyQTlNpzLat; participant_info=} @{tid=7; token=nQ_S838LjYT4mR6; participant_info=}
This is what I need to produce from export-csv:
Can anybody please point me in the right direction to transforming the 'participant_info' into valid json for the CSV export? - As you can tell I have little expierence with PowerShell other then using it for SharePoint. Thank you!
Upvotes: 0
Views: 52
Reputation: 25001
Your goal is to output an object with a custom set of properties (because it differs from the original object). This can be done with Select-Object and calculated properties.
$output |
Select-Object tid,token,
@{n='Firstname';e={$_.participant_info.Firstname}},
@{n='Lastname';e={$_.participant_info.Lastname}},
@{n='Email';e={$_.participant_info.Email}} |
Export-CSV testtt.csv -NoType
Upvotes: 2