首页 > 解决方案 > 在 azure 中创建 vm 并运行安装脚本

问题描述

我正在寻找一种方法来运行一个脚本,该脚本创建一个带有 rdp 端口​​的简单 windows vm 并在其上安装一个软件,以便为我们的客户提供一个简单的沙盒服务器用于测试目的。有没有一种简单的方法可以做到这一点,因为我已经挣扎了一段时间。

标签: azuredeploymentautomationdevops

解决方案


您应该为 Azure VM 使用自定义脚本扩展。根据您创建虚拟机的方式,您可以使用 powershell\cli\arm templates\rest api\sdk 来使用该扩展。

示例电源外壳:

$ProtectedSettings = @{"commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File \\filesvr\build\serverUpdate1.ps1"};

Set-AzureRmVMExtension -ResourceGroupName myRG 
    -Location myLocation ` 
    -VMName myVM ` 
    -Name "serverUpdate" 
    -Publisher "Microsoft.Compute" `
    -ExtensionType "CustomScriptExtension" ` 
    -TypeHandlerVersion "1.9" `
    -ProtectedSettings $ProtectedSettings

ARM 模板示例:https
://github.com/Azure/azure-quickstart-templates/tree/master/201-vm-custom-script-windows AZ cli 示例:https ://blogs.technet.microsoft.com/paulomarques /2017/02/13/executing-custom-script-extension-using-azure-cli-2-0-on-an-azure-linux-virtual-machine/


推荐阅读