powershell - Chocolatey 找不到 Windows 功能

标签 powershell octopus-deploy chocolatey

我正在使用 Octopus 部署在目标机器上运行 PowerShell 脚本,尝试安装 IIS。我正在使用下面的脚本并传递必要的参数。记录的内容让人相信调用是正确的,但它只是响应:

正在从 Chocolatey 包存储库安装包 IIS-WebServerRole...

17:11:48Info
Installing the following packages:
17:11:48Info
IIS-WebServerRole
17:11:48Info
By installing you accept licenses for the packages.
17:11:48Info
IIS-WebServerRole not installed. The package was not found with the source(s) listed.
17:11:48Info
 If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.
17:11:48Info
 Version: ""
17:11:48Info
 Source(s): "windowsFeatures"

代码:

$chocolateyBin = [Environment]::GetEnvironmentVariable("ChocolateyInstall", "Machine") + "\bin"
if(-not (Test-Path $chocolateyBin)) {
    Write-Output "Environment variable 'ChocolateyInstall' was not found in the system variables. Attempting to find it in the user variables..."
    $chocolateyBin = [Environment]::GetEnvironmentVariable("ChocolateyInstall", "User") + "\bin"
}

$cinst = "$chocolateyBin\cinst.exe"
$choco = "$chocolateyBin\choco.exe"

if (-not (Test-Path $cinst) -or -not (Test-Path $choco)) {
    throw "Chocolatey was not found at $chocolateyBin."
}

if (-not $ChocolateyPackageId) {
    throw "Please specify the ID of an application package to install."
}

$chocoVersion = & $choco --version
Write-Output "Running Chocolatey version $chocoVersion"

$chocoArgs = @()
if([System.Version]::Parse($chocoVersion) -ge [System.Version]::Parse("0.9.8.33")) {
    Write-Output "Adding --confirm to arguments passed to Chocolatey"
    $chocoArgs += @("-y", "")
}

if($ChocolateyPackageSource) {
    Write-Output "Adding --source to arguments passed to Chocolatey"
    $chocoArgs += @("-source", $ChocolateyPackageSource)
}

if (-not $ChocolateyPackageVersion) {
    Write-Output "Installing package $ChocolateyPackageId from the Chocolatey package repository..."
    & $cinst $ChocolateyPackageId $($chocoArgs)
} else {
    Write-Output "Installing package $ChocolateyPackageId version $ChocolateyPackageVersion from the Chocolatey package repository..."
    & $cinst $ChocolateyPackageId -version $ChocolateyPackageVersion $($chocoArgs)
}

根据我能找到的最新 Chocolatey 文档,这应该可行。任何想法为什么不会?我应该提到这是在 Azure Windows 2012 R2 VM 上。

最佳答案

我通过使用 chocolatey 的预发布版本来实现这个功能。 9.10.x-测试版……

我应该注意,仅执行 -pre 不足以让它安装包...出于某种原因,我还必须 -force 包让 chocolatey 自行更新。不确定这是否是设计使然。

关于powershell - Chocolatey 找不到 Windows 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37690467/

相关文章:

python - “Choco install python”在 AppVeyor 上失败,出现 1603

powershell - 通过 Install-BoxstarterPackage 将参数传递给 Boxstarter

powershell - 选项 -recurse 有时不适用于 PowerShell cmdlet get-childitem

file - 使用 PowerShell 复制没有文件的文件夹、没有文件夹的文件或所有内容

.net - 如何根据语义版本控制自动增加 Web 应用程序版本?

.net-core - Dotnet publish with .NET core 2.0 和 .NET Framework 项目

dependencies - 用于安装依赖项最新版本的 Nuspec 片段

c# - 在 powershell 中使用 nuget 外部工具

c# - 自定义 PSHostUserInterface 被 Runspace 忽略

continuous-integration - 在 Octopus 中,是否可以将文件上传到 Octopus,然后将其复制到目标计算机中的文件位置?