简体   繁体   English

从 git 存储库运行 Azure VM 扩展 Powershell 脚本

[英]Run Azure VM Extension Powershell script from git repository

I am trying to deploy a VM and run an extensions powershell script using ARM Templates.我正在尝试部署 VM 并使用 ARM 模板运行扩展 powershell 脚本。 The script below is responsible to run the extentions for the VM.下面的脚本负责运行 VM 的扩展。 As can be seen in the part:从部分可以看出:

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

The powershell will execute the script file from that location. powershell 将从该位置执行脚本文件。 I want to save the .ps1 file in a git repository and pass the link to the file instead of the local folder.我想将 .ps1 文件保存在 git 存储库中,并将链接传递给文件而不是本地文件夹。 Something like "commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -Uri https://raw.githubusercontent.com/.../install.ps1 How can I achieve this?类似于"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))]"
          }
        }
      }
    ]

The proper way to do it is to set URL https://raw.githubusercontent.com/.../install.ps1 (URL must be accessible for Azure ARM) to scriptURL parameter ( "[parameters('scriptURL')]" in "fileUris" settings) which is already in your template.正确的做法是将 URL https://raw.githubusercontent.com/.../install.ps1 ARM 必须可以访问 URL)到scriptURL参数( "[parameters('scriptURL')]""fileUris"设置中),它已经在您的模板中。

CustomScriptExtension will download all files fileUris into your VM to the extension folder, so you can use command as following: CustomScriptExtension 会将所有文件fileUris下载到您的 VM 到扩展文件夹中,因此您可以使用以下命令:

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

Note:笔记:

You can find CustomScriptExtension logs and downloaded files in VM:您可以在 VM 中找到 CustomScriptExtension 日志和下载的文件:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Powershell扩展的Azure VM安装程序挂起 - Azure VM setup with Extension from Powershell hangs 如何在使用ARM模板的Azure VM部署期间运行PowerShell脚本? - How to run a PowerShell script during Azure VM deployment with ARM template? 如何连接到Azure Windows VM并使用PowerShell运行远程脚本? - How Connect to a Azure Windows VM and run a remote script with PowerShell? Azure VM 运行 PowerShell 脚本不 Output - Azure VM Run PowerShell Script doesn't Output Terraform Azure 来自本地脚本的 VM 扩展自定义脚本 - Terraform Azure VM Extension Custom Script from Local Script 如何从 powershell 脚本重新启动 azure vm 并继续其余步骤 - How to reboot a azure vm from powershell script and continue the remaining steps 从VSTS到Azure PowerShell脚本到目标VM上的PowerShell脚本的双重跳过凭据 - Double hopping credentials from VSTS through Azure PowerShell script to PowerShell script on target VM 如何从远程计算机在Azure VM上运行脚本 - How to run a script on Azure VM from a remote machine 有没有办法通过 Azure 从 web 应用程序在 VM 上运行脚本? - Is there a way to run a script on a VM from a web app with Azure? PowerShell脚本将数据磁盘从一个Azure虚拟机移动到另一个VM - PowerShell script to move data disk from one azure vm to another vm
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM