Home > Enterprise >  Exporting usage details data from PowerShell variable to a .csv file is truncated
Exporting usage details data from PowerShell variable to a .csv file is truncated

Time:09-25

I'm just missing data for my usage details invoke-restmethod call. If I do this using postman or thunderclient it gives me the full details in json format. But when I set this up using powershell and export it it a .csv file I am missing part of my data.

Help?

usage details api: https://docs.microsoft.com/en-us/rest/api/consumption/usage-details/list

CodePudding user response:

The Invoke-RestMethod cmdlet sends HTTP and HTTPS requests to Representational State Transfer (REST) web services that return richly structured data.

PowerShell formats the response based to the data type.

You are missing some of your data because when the REST endpoint returns multiple objects, the objects are received as an array. If you pipe the output from Invoke-RestMethod to another command, it is sent as a single [Object[]] object. The contents of that array are not listed one by one for the next command on the pipeline.

Please check this Invoke-RestMethod document for more information.

The way you can solve the issue is by converting the output result to a CSV by using ConvertTo-CSV cmdlet. You have use format-table in PowerShell and specify which you want export or view. If you there are internal elements you need to do a loop and export it.

Please check this example of ConvertTo-CSV documentation for more information.

  • Related