我正在为全新的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.
如您所见,控制台中未检测到参数,但仍然可以执行参数说明
任何想法如何使其起作用?
答案 0 :(得分:0)
已通过更改脚本解决:
$dir = "$PSScriptRoot\packages.txt"
$pkgs = Get-Content -Path $dir
foreach ($string in $pkgs)
{
$command = "choco install -y $string"
iex $command
}
并删除"
中的packages.txt