使用Powershell下载文件 [英] Downloading a file with Powershell
问题描述
以下Google Doc导出为CSV,然后使用标准的Web浏览器自动下载: >://docs.google.com/spreadsheets/d/1wDD_Xm8IQYYYNFy9 ?format = csv
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
我正在尝试使用Powershell下载此文件而没有成功.我尝试使用Invoke-Webrequest,Start-BitsTransfer并使用webrequest对象,但是没有运气.
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.
已网址已更改.
推荐答案
Invoke-WebRequest
带有一个参数,用于将其结果存储在文件中:-OutFile
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
要确定登录发生的表单的布局,可以使用Invoke-WebRequests返回对象.它将收集有关HTML上的表单和字段的信息(可能仅适用于Windows).登录里程可能会因两因素身份验证"是否处于活动状态而有所不同.可能您可以创建一些不需要Auth的文件的秘密链接,或者Google可能允许您创建某种形式的私有访问令牌,可以将其随请求发送给Authorization-Header.
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.
这篇关于使用Powershell下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!