在 Azure 中创建虚拟机和 运行 安装脚本

creating vm and running installation script in azure

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

您应该对 Azure VM 使用 custom script extension。根据您创建虚拟机的方式,您可以使用 powershell\cli\arm templates\rest api\sdk 来使用该扩展。

powershell 示例:

$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/