【问题标题】:Run Azure VM Extension Powershell script from git repository从 git 存储库运行 Azure VM 扩展 Powershell 脚本
【发布时间】:2021-09-28 17:39:09
【问题描述】:

我正在尝试部署 VM 并使用 ARM 模板运行扩展 powershell 脚本。 下面的脚本负责运行 VM 的扩展。 从部分可以看出:

 "commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File arm-modules/../../install.ps1 '

powershell 将从该位置执行脚本文件。我想将 .ps1 文件保存在 git 存储库中,并将链接传递给文件而不是本地文件夹。 类似"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -Uri https://raw.githubusercontent.com/.../install.ps1 我怎样才能做到这一点?

"resources": [
      {
        "type": "Microsoft.Compute/virtualMachines/extensions",
        "name": "[concat(parameters('virtualMachineName'), '/' ,parameters('virtualMachineName'), 'installGW')]",
        "apiVersion": "2019-07-01",
        "location": "[parameters('location')]",
        "tags": {
          "vmname": "[parameters('virtualMachineName')]"
        },
        "properties": {
          "publisher": "Microsoft.Compute",
          "type": "CustomScriptExtension",
          "typeHandlerVersion": "1.7",
          "autoUpgradeMinorVersion": true,
          "settings": {
            "fileUris": [
              "[parameters('scriptURL')]"
            ]
          },
          "protectedSettings": {
            "commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File arm-modules/.../.../install.ps1 ', if(equals(parameters('existingDataFactoryVersion'), 'V2'), listAuthKeys(parameters('irId'), '2017-09-01-preview').authKey1, listAuthKeys(parameters('irId'), '2015-10-01').key1))]"
          }
        }
      }
    ]

【问题讨论】:

    标签: azure powershell azure-devops azure-resource-manager


    【解决方案1】:

    正确的做法是将 URL https://raw.githubusercontent.com/.../install.ps1(Azure ARM 必须可以访问 URL)设置为模板中已有的 scriptURL 参数("fileUris" 设置中的"[parameters('scriptURL')]")。

    CustomScriptExtension 会将所有文件fileUris 下载到您的 VM 到扩展文件夹中,因此您可以使用以下命令:

     "commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File install.ps1 '
    

    注意:

    您可以在 VM 中找到 CustomScriptExtension 日志和下载的文件:

    C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension
    C:\Packages\Plugins
    

    【讨论】:

      猜你喜欢
      • 2013-05-12
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 2022-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多