0

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=}

Export-CSV produces: enter image description here

This is what I need to produce from export-csv: enter image description here

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!

2
  • 1
    That's not json. $output looks like an object converted to a string by write-host. Commented Dec 22, 2020 at 14:03
  • Thank you for clarifying that :) Commented Dec 22, 2020 at 14:21

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. This works and I will research into Select-Object now <3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.