无法使用参数循环安装Chocolatey软件包

问题描述 投票:0回答:1

我正在为全新的Windows安装创建chocolatey powershell脚本。我的脚本是:

$dir = "$PSScriptRoot\packages.txt"
$pkgs = Get-Content -Path $dir
foreach ($string in $pkgs)
{
    choco install -y $string
}

packages.txt中,我有我的包裹清单。列表如下所示:

"notepadplusplus.install --x86"
"firefox"
...

如果我使用参数,它总是会给我错误。错误消息是:

Chocolatey v0.10.15
Installing the following packages:
notepadplusplus.install --x86
By installing you accept licenses for the packages.
notepadplusplus.install --x86 not installed. The package was not found with the source(s) listed.
 Source(s): 'https://chocolatey.org/api/v2/'
 NOTE: When you specify explicit sources, it overrides default sources.
If the package version is a prerelease and you didn't specify `--pre`,
 the package may not be found.
Please see https://chocolatey.org/docs/troubleshooting for more
 assistance.

如果不使用任何参数,都不会给我错误。但是,当我尝试在控制台中手动键入choco install -y notepadplusplus.install --x86"时,消息为:

Chocolatey v0.10.15
Installing the following packages:
notepadplusplus.install
By installing you accept licenses for the packages.
Progress: Downloading notepadplusplus.install 7.8.2... 100%

notepadplusplus.install v7.8.2 [Approved]
notepadplusplus.install package files install completed. Performing other installation steps.
Installing 32-bit notepadplusplus.install...
notepadplusplus.install has been installed.

如您所见,在控制台中未检测到参数,但仍按照参数说明进行操作

任何想法如何使其起作用?

powershell loops parameters chocolatey
1个回答
0
投票

通过更改脚本解决:

$dir = "$PSScriptRoot\packages.txt"
$pkgs = Get-Content -Path $dir
foreach ($string in $pkgs)
{
    $command = "choco install -y $string"
    iex $command
}

并删除"中的packages.txt

© www.soinside.com 2019 - 2024. All rights reserved.