在Invoke-WebRequest处隐藏Powershell进度栏的批处理文件

时间:2018-12-01 15:28:41

标签: powershell batch-file

我想制作一个批处理脚本,该脚本在Invoke-WebRequest命令中隐藏Powershell的进度条。我已经尝试过:

powershell.exe -command "$progressPreference = 'silentlyContinue'"

但是它不起作用。我无法添加更多信息。

这是我的代码:

powershell.exe -command "$progressPreference = 'silentlyContinue'"
powershell -command "INVOKE-WEBREQUEST http://download1502.mediafire.com/blahblah/blahblah2 -OUTFILE %TEMP%\Sibelius751209INStall100.tmp\AvidPF.zip"

1 个答案:

答案 0 :(得分:1)

您两次调用powershell.exe。您在第一个调用中设置的任何变量仅在第一个调用中存在。您必须使用一个电话。

powershell.exe -command "$progressPreference = 'silentlyContinue'; Invoke-WebRequest http://download1502.mediafire.com/blahblah/blahblah2 -OutFile '$Env:TEMP\Sibelius751209INStall100.tmp\AvidPF.zip'"

为了获得更好的可重复使用性,我将保存一个.ps1文件download.ps1

$progressPreference = "silentlyContinue"

$url = $args[0]
$outfile = $args[1]

Invoke-WebRequest $url -Outfile $outfile

并从cmd.exe /批处理文件中调用

set "URL=http://download1502.mediafire.com/blahblah/blahblah2"
set "OUTFILE=%TEMP%\Sibelius751209INStall100.tmp\AvidPF.zip"

powershell -File download.ps1 "%URL%" "%OUTFILE%"