Yuval Perelman
Yuval Perelman

Reputation: 4809

creating vm and running installation script in azure

I'm looking for a way to run a script that creates a simple windows vm with rdp port and installs a software on it in order give our clients a simple sand boxed server for testing purposes. Is there a simple way to do that as I've been struggling for a while now.

Upvotes: 0

Views: 156

Answers (1)

4c74356b41
4c74356b41

Reputation: 72171

You should use custom script extension for Azure VM. Depending on how you create vms you can use powershell\cli\arm templates\rest api\sdk to use that extension.

sample 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 Template sample: https://github.com/Azure/azure-quickstart-templates/tree/master/201-vm-custom-script-windows
AZ cli sample: https://blogs.technet.microsoft.com/paulomarques/2017/02/13/executing-custom-script-extension-using-azure-cli-2-0-on-an-azure-linux-virtual-machine/

Upvotes: 1

Related Questions