Kamsiinov
Kamsiinov

Reputation: 1486

Azure custom extension fails with Error message:"Finished executing command"

I am starting to test custom extensions in Azure and started with very simple json and ps1 script. My json file looks like this:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "vmName": {
        "type": "string"
    }
},
"resources": [
    {
        "type": "Microsoft.Compute/virtualMachines/extensions",
        "name": "[concat(parameters('vmName'),'/RunDateTimeScript')]",
        "apiVersion": "2015-06-15",
        "location": "[resourceGroup().location]",
        "properties": {
            "publisher": "Microsoft.Compute",
            "type": "CustomScriptExtension",
            "typeHandlerVersion": "1.8",
            "autoUpgradeMinorVersion": true,
            "settings": {
                "fileUris": [
                    "https://github.com/username/repo/blob/master/writedatetime.ps1"
                ],
                "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File writedatetime.ps1"
            }
        }
    }
]
}

And my powershell script is a oneliner:

(Get-Date).DateTime | Out-File "C:\Testing.txt" -Append

However, when I run the usual powershell deployment command:

New-AzureRmResourceGroupDeployment -ResourceGroupName MyResources -TemplateFile .\extensionexample.json -vmName MyVmName01

I get failed as a result and:

"message": "VM has reported a failure when processing extension 'RunDateTimeScript'. Error message: \"Finished executing command\"."

So what I am doing wrong and how to fix this?

Upvotes: 0

Views: 1432

Answers (1)

Kamsiinov
Kamsiinov

Reputation: 1486

The problem with this was pretty dumb. I used the wrong url for github as it should be the raw instead of the one in template. i.e https://raw.githubusercontent.com/username/repo/master/script.ps1

Upvotes: 1

Related Questions