I'm using Powershell and a JSON file to create new VM's. The last part of the JSON file instructs the newly-created VM to run a file. I can verify (via the Azure portal and via Powershell) that the file exists at the URL given in the JSON file.
Yet the VM finishes with result ProvisioningState:Failed because VM has reported a failure when processing extension 'CustomScriptExtension'. Error message: "Finished executing command" which is frustratingly ambivalent. (We've also had problems with the domainjoin CustomScriptExtension which also "failed" with a "success" message.)
The script, which is a simple CMD file, should create the file C:\Users\Public\Documents\runonce.log, but this does not happen so I guess the file does not run.
However, the VM is created, and I can then manually log in and run the file just fine. So it should not be a matter of user privileges or such.
Edit: This comment states that "CustomScriptExtension does not run with local admin priviledges", but I don't think that's the problem here.
What am I missing?
Here's the relevant part of the JSON:
...
"resources": [
...
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(parameters('vmName'),'/CustomScriptExtension')]",
"apiVersion": "2015-05-01-preview",
"location": "[resourceGroup().location]",
"dependsOn": ["[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"],
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.2",
"settings": {
"fileUris": ["[concat(parameters('scriptFilePath'),parameters('scriptFileName'))]"],
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -file ',parameters('scriptFileName'))]"
}
}
}]
and I have verified that scriptFilePath and scriptFileName are https://euwest2766.blob.core.windows.net/script/ and run-once.cmd which corresponds to the blob URL shown in Azure. I have even tried putting that Azure Blob URL into the JSON, with the same result.
This won't work because you are trying to run a batch file through Powershell.
you would need to change this -
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -file ',parameters('scriptFileName'))]"
to this
"commandToExecute": "[concat('cmd /s',parameters('scriptFileName'))]"
That should execute as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With