Powershell 如何将调用RestMethod的数据结果获取到CSV文件中?

Powershell 如何将调用RestMethod的数据结果获取到CSV文件中?,powershell,Powershell,我正在尝试将REST调用的结果数据获取到CSV文件中 我的代码是: $results = Invoke-RestMethod -Method Get -Uri $url -Header $bearer -ContentType 'application/json' $results 而它又带来了: data

我正在尝试将REST调用的结果数据获取到CSV文件中

我的代码是:

$results = Invoke-RestMethod -Method Get -Uri $url -Header $bearer -ContentType 'application/json' 
$results
而它又带来了:

data ---- {@{type=flight-offer; id=1559566119876--1838046263; offerItems=System.Object[]}, @{type=flight-offer; id=15595... 我想将每个offerItems对象的值获取到CSV文件中。

展开数据属性并将嵌套对象导出到CSV:

$results |
    Select-Object -Expand data |
    Export-Csv 'C:\path\to\output.csv' -NoType
但是,由于您的数据对象显然包含一个数组offerItems=System.Object[],因此您必须首先将该数组转换为字符串,例如:

... |
    Select-Object -Expand data |
    Select-Object *,@{n='offerItems';e={$_.offerItems -join ','}} -Exclude offerItems |
    ...
合并操作可能会有所不同,具体取决于数组所保存的数据类型