如何将下载的 CSV 数据从 Invoke-RestMethod 管道传输到 Import-CSV? [英] How to pipe downloaded CSV data from Invoke-RestMethod to Import-CSV?

查看:52
本文介绍了如何将下载的 CSV 数据从 Invoke-RestMethod 管道传输到 Import-CSV?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何代表或至少查看这个数据?

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.

明显的解析错误不太合适,因为 Import-CSV 在文件上运行良好.类似地,该文件太长"也同样如此.没有意义,因为下载的文件工作正常.

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.

也许我只需要拨动一个开关,否则 powershell 会卡在大"屏幕上.文件?

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

推荐答案

$labs_csv | ConvertFrom-Csv | Format-Table

这个,从 $labs_csv 开始,你存储它,应该允许你至少查看数据.请注意,ConvertFrom-Csv 和 Import-csv 之间的区别与数据是否来自文件有关.

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.

这篇关于如何将下载的 CSV 数据从 Invoke-RestMethod 管道传输到 Import-CSV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆