Custom Script Extension - Gary-Moore/developmentwiki GitHub Wiki

The Custom Script Extension downloads and executes scripts on Azure virtual machines. This extension is useful for post deployment configuration, software installation, or any other configuration / management task. Scripts can be downloaded from Azure storage or GitHub, or provided to the Azure portal at extension run time. The Custom Script extension integrates with Azure Resource Manager templates, and can also be run using the Azure CLI, PowerShell, Azure portal, or the Azure Virtual Machine REST API.

Custom Link Extension Documentation

Enable IIS on a VM

Azure cli to run script extension

az vm extension set \
  --resource-group ff5a02e5-7220-47f5-be00-27311b264c60 \
  --vm-name myVM \
  --name CustomScriptExtension \
  --publisher Microsoft.Compute \
  --settings '{"fileUris":["https://raw.githubusercontent.com/MicrosoftDocs/mslearn-welcome-to-azure/master/configure-iis.ps1"]}' \
  --protected-settings '{"commandToExecute": "powershell -ExecutionPolicy Unrestricted -File configure-iis.ps1"}'

Powershell Script to run on server

# Install IIS.
dism /online /enable-feature /featurename:IIS-WebServerRole

# Set the home page.
Set-Content `
  -Path "C:\\inetpub\\wwwroot\\Default.htm" `
  -Value "<html><body><h2>Welcome to Azure! My name is $($env:computername).</h2></body></html>"

Open Firewall Port

az vm open-port \
  --name myVM \
  --resource-group ff5a02e5-7220-47f5-be00-27311b264c60 \
  --port 80

Verify

az vm show \
  --name myVM \
  --resource-group [sandbox resource group name] \
  --show-details \
  --query [publicIps] \
  --output tsv

Scale up VM

az vm resize \
  --resource-group [sandbox resource group name] \
  --name myVM \
  --size Standard_DS3_v2

Verify

az vm show \
  --resource-group [sandbox resource group name] \
  --name myVM \
  --query "hardwareProfile" \
  --output tsv
⚠️ **GitHub.com Fallback** ⚠️