How to pipe downloaded CSV data from Invoke-RestMethod to Import-CSV?

懵懂的女人 提交于 2020-12-15 04:54:51

问题


How can I represent, or at least view, this data?

PS /home/nicholas> 
PS /home/nicholas> $labs='http://www.bccdc.ca/Health-Info-Site/Documents/BCCDC_COVID19_Dashboard_Lab_Information.csv'       
PS /home/nicholas> 
PS /home/nicholas> $labs_csv=Invoke-RestMethod -Method Get -Uri $labs -Headers @{"Content-Type" = "text/csv"}               
PS /home/nicholas> 
PS /home/nicholas> $labs_csv
"Date","Region","New_Tests","Total_Tests","Positivity","Turn_Around"
2020-01-23,"BC",2,2,0,32
2020-01-23,"Fraser",0,0,0,0
2020-01-23,"Interior",0,0,0,0
...
2020-11-19,"Unknown",138,17222,0,37.4
2020-11-19,"Vancouver Coastal",2923,337615,5.12,28.5
2020-11-19,"Vancouver Island",1682,118623,1.4,12.7

PS /home/nicholas> 

Manually downloading the file, then importing, works fine.

the apparent parsing error doesn't quite fit, because Import-CSV works fine on the file. Similarly, that the file is "too long" doesn't make sense as the file which was downloaded works fine.

All else being equal, of course.

Perhaps I just need to flip a switch, else powershell will choke on the "large" file?


回答1:


$labs_csv | ConvertFrom-Csv | Format-Table

This, starting with $labs_csv as you stored it, should allow you to at least view the data. Note that the difference between ConvertFrom-Csv and Import-csv has to do with whether or not the data comes from a file.

You may or may not wish to store your data in a file.



来源:https://stackoverflow.com/questions/64969211/how-to-pipe-downloaded-csv-data-from-invoke-restmethod-to-import-csv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!