首页 > 解决方案 > 如何使用 powershell 下载接受许可证的文件

问题描述

我正在尝试使用 powershell 从以下链接下载软件包。 https://www.tenable.com/downloads/nessus-agents 我没有这些包的直接链接,当我点击下载时,它要求同意。我能够使用下面显示的命令在 Linux 上做到这一点。请告诉我如何在Windows中做到这一点。

"wget  --no-check-certificate --post-data='accept="I accept the terms of this license"&x=""&sid=5mcia8gchg28attkc9oarah153&p=NessusAgent-7.4.2-amzn.x86_64.rpm' 'https://www.tenable.com/downloads/nessus-agents' -O NessusAgent-7.4.2-amzn.x86_64.rpm"

无法使用 invoke-webrequest 找到任何尝试过的选项

调用-RestMethod -Uri ' https://www.tenable.com/downloads/nessus-agents '

标签: powershellwgetinvoke-webrequest

解决方案


有一个 GET 查询字符串参数表示接受。

只需添加i_agree_to_tenable_license_agreement=true到您的查询字符串参数。

Invoke-WebRequest -Uri 'https://www.tenable.com/downloads/api/v1/public/pages/nessus-agents/downloads/9762/download?i_agree_to_tenable_license_agreement=true' -OutFile 'NessusAgent-7.4.2-x64.msi'

您可以轻松地从其 API 端点获取其他文件的 ID,如下所示:

(Invoke-WebRequest -Uri 'https://www.tenable.com/downloads/api/v1/public/pages/nessus-agents' | ConvertFrom-Json).downloads | Format-Table -AutoSize

推荐阅读