Downloading a file with Powershell

我只是一个虾纸丫 提交于 2020-01-10 17:46:13

问题


The following Google Doc gets exported to CSV and is then downloaded automatically using a standard Web Browser: https://docs.google.com/spreadsheets/d/1wDD_Xm8IQYuYNefv9cOJ_7afTLImHgYA05pfN3qY63E/export?format=csv

I'm trying to download this file using Powershell without success. I tried using Invoke-Webrequest, Start-BitsTransfer and using a webrequest object but no luck there.

EDITED: changed url.


回答1:


Invoke-WebRequest comes with a parameter to store its result in a file: -OutFile

Invoke-WebRequest URL -OutFile c:\file.ext

If you need authorization before you can send a request like this:

Invoke-WebRequest URL /* whatever is neccesary to login */ -SessionVariable MySession
Invoke-WebRequest URL -WebSession $MySession

To determine the layout of the form where the login happens, you can use Invoke-WebRequests return object. It'll collect information about forms and fields on the HTML (might be Windows only). Mileage of logging in may vary with things like Two-Factor-Auth active or not. Probably you can create some secret link to your file which does not need Auth or possibly google allows you to create a private access token of some sort, which can be send aus Authorization-Header alongside your request.



来源:https://stackoverflow.com/questions/51225598/downloading-a-file-with-powershell

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