powershell - 安装时编辑 Chocolatey 源

标签 powershell azure azure-resource-manager chocolatey

我使用 Chocolatey 和 Azure ARM 模板来构建 VM,然后安装所需的软件。我知道有一种方法可以配置安装 Chocolatey 后 Chocolatey 从中提取安装文件的位置,但是有人知道是否有一种方法可以预先配置在 Chocolatey 安装之前(或期间)的源位置?

我想从头到尾进行完全无人值守的安装,因此必须在安装后和安装应用程序之前编辑 Chocolatey 配置文件,这就否定了整个无人值守的想法。

我在这里查看了 Chocolatey PS1 安装脚本:https://chocolatey.org/install.ps1

遗憾的是,我无法在其中找到任何可以编辑以修改 Choco 包的源位置的内容。

这是自定义脚本扩展,它是 ARM 模板的一部分,用于通过 Azure 安装 VM

{
  "name": "[concat(parameters('virtualMachineName'),'/chocolatey')]",
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "location": "[resourceGroup().location]",
  "apiVersion": "2015-06-15",
  "dependsOn": [
    "[concat('Microsoft.DevTestLab/schedules/', 'shutdown-computevm-', parameters('virtualMachineName'))]"
  ],
  "properties": {
    "publisher": "Microsoft.Compute",
    "type": "CustomScriptExtension",
    "typeHandlerVersion": "1.9",
    "autoUpgradeMinorVersion": true,
    "settings": {
      "fileUris": [
        "[concat(parameters('setupChocolatelyScriptLocation'),parameters('setupChocolateyScriptFileName'))]"
      ],
      "commandToExecute": "[concat('powershell -ExecutionPolicy bypass -File ', parameters('setupChocolateyScriptFileName'), ' -chocoPackages ',parameters('chocoPackages'))]"
    }
  }
},

最佳答案

Chocolatey 安装完成后,您可以使用 choco source 命令来更改/添加/删除 Chocolatey 使用的可用源。

此命令记录在此处:

https://chocolatey.org/docs/commands-sources

但举个例子,您只需运行:

choco source add -n=bob -s="https://somewhere/out/there/api/v2/"

您可以定义对您在其中定义的 ARM 模板部分的依赖关系,以便仅在安装 Chocolatey 后运行。

另一种方法是在安装命令中指定要使用的源,例如:

choco install packageA -y --source https://somewhere/out/there/api/v2/

关于powershell - 安装时编辑 Chocolatey 源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50251522/

相关文章:

powershell - Powershell中是否可以查询对象的属性页详细信息

Powershell 启动进程 : This command cannot be executed due to the error: Access is denied

c# - 另外获取刷新 token 以使用 Microsoft.Identity.Client 访问 token

Azure 函数与 EntityFramework + DI

c# - SignalR 使用 Azure EventHub 进行扩展

excel - 在宏 VBA 中将操作参数传递给 SchTasks

C# Exchange PowerShell pipeLine Invoke 正在为 null 参数值引发 CmdletInvocationException

azure - 用于识别 Azure Log Analytics 可用 SKU 的编程方法

virtual-machine - 如何在资源管理器门户中为 Azure 虚拟机配置 WinRM

powershell - 使用 PowerShell 获取 Azure DocumentDB 主键