我试图使用Invoke-WebRequest下载一个zip文件,并将它提供给Extract-Archive。 我不是100%的热衷于在这个过程中不使用磁盘(这将是很好),但如果一个临时文件清单,它会很好,如果它在过程后消失。 我正在尝试这个命令(和几个类似的):
Invoke-WebRequest https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-beta.8/PowerShell-6.0.0-beta.8-win-x64.zip | Extract-Archive -DestinationPath C:\Kellekek\Microsoft\PowerShell\6.0.0-beta.8
但是下载完成后就会挂起。 我做错了什么或是在PS核心中的错误?
你做错了。 Invoke-WebRequest
返回WebResponseObject
types的对象。 该对象具有以下属性:
$x |get-member TypeName: Microsoft.PowerShell.Commands.WebResponseObject Name MemberType Definition ---- ---------- ---------- Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToString Method string ToString() BaseResponse Property System.Net.WebResponse BaseResponse {get;set;} Content Property byte[] Content {get;set;} Headers Property System.Collections.Generic.Dictionary[string,string] Headers {get;} RawContent Property string RawContent {get;set;} RawContentLength Property long RawContentLength {get;} RawContentStream Property System.IO.MemoryStream RawContentStream {get;} StatusCode Property int StatusCode {get;} StatusDescription Property string StatusDescription {get;}
Content
听起来有希望 你可以尝试使用这个Extract-Archive
,我不能尝试它,因为我的PowerShell不知道这个cmdlet,我不知道你在哪里得到它。
那将是:
(Invoke-WebRequest https://your/url/...).Content | Extract-Archive -DestinationPath C:\Kellekek\Microsoft\PowerShell\6.0.0-beta.8
如果这不起作用,你可以使用临时文件,如下所示:
# Create a new temporary file $tmp = New-TemporaryFile # Store the download into the temporary file Invoke-WebRequest -OutFile $tmp https:/..... # extract the temporary file (again, this is untested) $tmp | Extract-Archive # remove temporary file $tmp | Remove-Item