Install Custom Script Extension in Azure Linux VM using the REST API

Figuring out how to install Microsoft Azure VM extensions using the REST API can be a bit of a pain — especially when you don’t know the Publisher name, version, or specific name of the extension. While these values are available for a few of the Windows extensions, the Linux ones are harder to find. Recently I had to figure out the settings for the Linux version of the Custom Script Extension, as well as how to specify the command to be run. After a bit of searching I found this and decided to share as it was certainly not as easy to find as would have been nice.

Note that the bits that you want are in the <ResourceExtensionReference> tag. Also note that the <Value>‘s for both of the <ResourceExtensionParameterValue> tags are base64-encoded strings built from JSON objects of the following form:

    "fileUris": [""],
    "commandToExecute": "sh"

In the public config, fileUris can be a list of one or more blobs to be downloaded from the Azure Storage account whose information is contained in the private config:

    "storageAccountName": "MyAccount",

In C# you can base64 encode these values as such:

// Where "paramString" is the name of the string you want to base64 encode
String encodedValues = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(paramString));

Finally, a full example of the XML and parameters. Note that you’ll replace the <!–Public Config–> and <!–Private Config–> with the base64 encoded versions of your public and private config parameters.

<Deployment xmlns="">
              <Value><!--Public Config--></Value>
              <Value><!--Private Config--></Value>

Demo JSON objects are from this Azure blog post.

No comments yet.

Leave a Reply

Proudly made in Canada