【问题标题】:Found error with my Batch file while trying to download a file from a website尝试从网站下载文件时发现我的批处理文件出错
【发布时间】:2021-06-29 21:28:34
【问题描述】:

我试图创建一个从网站下载文件的批处理文件,在执行批处理文件后我发现了这个错误。

"Downloading CCleaner..."
Invoke-WebRequest : A positional parameter cannot be found that accepts argument '-'.
At line:1 char:1
+ Invoke-WebRequest https://download.ccleaner.com/ccsetup578.exe - Outf ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

"Done!"
Press any key to continue . . .

下面是实际代码。

@echo off
echo "Downloading CCleaner..."
powershell -Command "Invoke-WebRequest https://download.ccleaner.com/ccsetup578.exe - Outfile setup.exe"
echo "Done!"
pause

Error Screenshot.

【问题讨论】:

    标签: powershell batch-file


    【解决方案1】:

    去掉“-”和“OutFile”之间的空格

    @echo off
    echo "Downloading CCleaner..."
    powershell -Command "Invoke-WebRequest https://download.ccleaner.com/ccsetup578.exe -Outfile setup.exe"
    echo "Done!"
    pause
    

    【讨论】:

    • 您好,它适用于我的 Windows 10,但不适用于 Windows Server 2016。可能是什么问题?
    • 第一次以用户身份打开 Web 浏览器时,您必须接受 Internet Explorer 提示,这也适用于运行 Invoke-WebRequest。您应该得到的提示应该是“无法解析响应内容,因为 Internet Explorer 引擎不可用,或者 Internet Explorer 的首次启动配置未完成。指定 UseBasicParsing 参数并重试。`您可以通过将 -UseBasicParsing 添加到您的 Invoke-WebRequest 行来解决此问题。
    • 我尝试替换并添加到它旁边。没用。
    • 能否给我们您当前的代码和错误信息?
    猜你喜欢
    • 1970-01-01
    • 2011-07-12
    • 2021-07-11
    • 2018-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-19
    • 2011-06-04
    相关资源
    最近更新 更多