Q
Manage Learn to apply best practices and optimize your operations.

Use the Azure Custom Script Extension for your Azure VMs

To execute custom scripts for Azure Windows and Linux VMs to support post-deployment configurations, you'll have to download the Azure Custom Script Extension plug-in.

It's easy to execute custom scripts -- including PowerShell scripts -- in a VM running in on-premises Hyper-V hosts....

All you need to do is create a script that the destination VM can support and then run it via PowerShell Direct or copy the script to the VM. Azure also supports executing custom scripts in Azure VMs, but the way you execute them is slightly different.

Azure Custom Script Extension is a plug-in designed to only work with Azure VMs. It can be used to execute scripts stored in an Azure blob container or in a valid URL that's accessible by Azure Portal and PowerShell command lines. Before you execute scripts inside Azure VMs, you'll be required to decide the source of the script and resource group name in which the Azure VM is located. If your script is stored in an Azure blob container, you'll be required to supply the storage account name, storage account key and blob container where the script is located. By executing the command below, you're executing a script stored in an Azure blob container named VMScripts:

Set-AzureRMVMCustomScriptExtension –ResourceGroupName "RSGroup1" –Location "Central US" –VMName "SQLVM" -StorageAccountName "StorageAccount1" –StorageAccountKey {StorageAccountKeyHere} –FileName "ThisScript.PS1" –ContainerName "VMScripts"

If you have a script available in other locations, such as GitHub, you'll be required to download the script from GitHub to the Azure VM as it's shown in the command below:

Set-AzureRMVMCustomScriptExtension –ResourceGroupName "RSGroup1" –VMName "SQLVM" –Name "VMScripts" –FileURI {Complete Script Path here} –Run "ScriptFile.PS1" –Location "Central US"

Azure Custom Script Extension is available for both Azure Windows and Linux VMs. You can execute any PowerShell script in Azure Windows VMs and any Bash scripts in Azure Linux VMs.

Troubleshooting issues

If you face any issues during execution of the scripts, you might want to check execution logs found under C:\WindowsAzure\Logs\Plugins\
Microsoft.Compute.CustomScriptExtension in Azure VMs. If the script failed to execute, make sure the script was downloaded to Azure VMs from either a storage blob container or URL. Scripts are downloaded to the C:\
Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.*\Downloads\ location in the Azure VM.

You might want to execute custom scripts using Azure Custom Script Extension to support post-deployment configurations, such as configuring OS settings and installing line-of-business applications.

Next Steps

Learn more about Azure Security Center

Solve API problems in Azure

Avoid downtime with Azure availability sets

This was last published in November 2017

Dig Deeper on Cloud computing architecture

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Join the conversation

1 comment

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

What other post-deployment configurations can be executed using Azure's custom script plug-in?
Cancel

-ADS BY GOOGLE

SearchVMware

SearchWindowsServer

SearchCloudComputing

SearchVirtualDesktop

SearchDataCenter

Close