1

I'm looking into how I can run commands remotely on a freshly deployed windows VM in Azure, and have a few basic questions.

It seems like the 'Custom Script Extension' is the answer, but according to the documentation, is stated as only applicable for Server operating systems:

https://learn.microsoft.com/en-us/azure/virtual-machines/windows/extensions-customscript

This is correct I assume? And if so, what about non-server windows OS?

Moving on, I have tried using the Custom Script Extension against a Windows Server 2016 data centre, based on the MS tutorial at: https://learn.microsoft.com/en-us/azure/virtual-machines/scripts/virtual-machines-linux-cli-sample-create-vm-nginx?toc=%2fazure%2fvirtual-machines%2flinux%2ftoc.json

My aim was to create a new Windows VM and instruct it to simply create a new dir after deployment.

CLI Steps:

1. Create a resource group
2. Create a new virtual machine (Server 2016 Datacentre) 
3. Finally, run the following command:

az vm extension set --publisher Microsoft.Azure.Extensions --version 2.0 --name CustomScript --vm-name (nameOfMyVM) --resource-group (nameOfMyResourceGroup) --settings '{"commandToExecute":"powershell.exe md c:\testFolder"}'

This returns the error:

Handler 'Microsoft.Azure.Extensions.CustomScript' has reported failure for VM Extension 'CustomScript' with terminal error code '1007' and error message: 'Install failed for plugin (name: Microsoft.Azure.Extensions.CustomScript, version 2.0.3) with exception The specified executable is not a valid application for this OS platform.'

Should extra steps have been involved to accomplish this action on the VM successfully?

Thanks

David
  • 197
  • 3
  • 19

2 Answers2

2

As 4c74356b41 said, you are using a Linux Script extension, for windows server, we should use CustomScriptExtension and the publisher is Microsoft.Compute.

We can use CLI 2.0 to set extension to windows VM, here are my steps:
1.create a json file, like this:

{
  "commandToExecute": "powershell.exe mkdir C:\\test321"
}

2.Use CLI to set extension for windows VM: we can use this command script:

az vm extension set -n CustomScriptExtension --publisher Microsoft.Compute --version 1.8 --vm-name jasonvm --resource-group vmm --settings C:\Users\jason\Desktop\test\jasontest5.json

Here is the result:

C:\Users\jason>az vm extension set -n CustomScriptExtension --publisher Microsoft.Compute --version 1.8 --vm-name jasonvm --resource-group vmm --settings C:\Users\jason\Desktop\test\jasontest5.json
{
  "autoUpgradeMinorVersion": true,
  "forceUpdateTag": null,
  "id": "/subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29a7b15/resourceGroups/vmm/providers/Microsoft.Compute/virtualMachines/jasonvm/extensions/CustomScriptExtension",
  "instanceView": null,
  "location": "centralus",
  "name": "CustomScriptExtension",
  "protectedSettings": null,
  "provisioningState": "Succeeded",
  "publisher": "Microsoft.Compute",
  "resourceGroup": "vmm",
  "settings": {
    "commandToExecute": "powershell.exe mkdir C:\\test321"
  },
  "tags": null,
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "typeHandlerVersion": "1.8",
  "virtualMachineExtensionType": "CustomScriptExtension"
}

==========================================
Update:

As David said, we can use this command without json file:

az vm extension set -n CustomScriptExtension --publisher Microsoft.Compute --version 1.8 --vm-name DVWinServerVMB --resource-group DVResourceGroup --settings "{'commandToExecute': 'powershell.exe md c:\\test'}"
Jason Ye
  • 13,710
  • 2
  • 16
  • 25
  • 1
    Thanks Jason, that did the trick! And can also be run without json file: az vm extension set -n CustomScriptExtension --publisher Microsoft.Compute --version 1.8 --vm-name DVWinServerVMB --resource-group DVResourceGroup --settings "{'commandToExecute': 'powershell.exe md c:\\test'}" – David May 12 '17 at 09:22
  • Thank you for your share, I will update this to this answer. – Jason Ye May 12 '17 at 09:25
  • Thank you! Was dealing with this issue when trying to install and extension from ansible. No where does ansible tell you about the differences in extensions and microsofts documents are hard to find on this subject. You're a lifesaver – dsutherland Feb 22 '18 at 14:46
1

you are using a Linux Script extension against windows VM, try and guess how successful could that be? This is the link you are looking for:
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/extensions-customscript?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json

Also, custom script extension is the way to go, or you might use DSC extension, or Azure Automation, depending on complexity of what you actually need.

4c74356b41
  • 69,186
  • 6
  • 100
  • 141