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://docs.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://docs.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
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:
2.Use CLI to set extension for windows VM: we can use this command script:
Here is the result:
==========================================
Update:
As David said, we can use this command without json file:
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://docs.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.