az vmss run-command

Commands

az vmss run-command invoke Execute a specific run command on a Virtual Machine Scale Set instance.
az vmss run-command list Lists all available run commands for a subscription in a location.
az vmss run-command show Gets specific run command for a subscription in a location.

az vmss run-command invoke

Execute a specific run command on a Virtual Machine Scale Set instance.

az vmss run-command invoke --command-id
[--ids]
[--instance-id]
[--name]
[--parameters]
[--resource-group]
[--scripts]
[--subscription]

Examples

Install nginx on a VMSS instance.

az vmss run-command invoke -g MyResourceGroup -n MyVMSS --command-id RunShellScript \ --instance-id 0 --scripts "sudo apt-get update && sudo apt-get install -y nginx"

Invoke a run-command with parameters on a VMSS instance.

az vmss run-command invoke -g MyResourceGroup -n MyVMSS --command-id RunShellScript \ --instance-id 4 --scripts 'echo $1 $2' --parameters hello world

Invoke command on all VMSS instances using the VMSS instance resource IDs. Note: "@-" expands to stdin.

az vmss list-instances -n MyVMSS -g my-rg --query "[].id" --output tsv | \
az vmss run-command invoke --scripts 'echo $1 $2' --parameters hello world  \
    --command-id RunShellScript --ids @-

Run powershell script on a windows VMSS instance with parameters. Script supplied inline. Be wary of single-quoting in CMD.exe.

az vmss run-command invoke  --command-id RunPowerShellScript --name win-vm -g my-resource-group \
    --scripts 'param([string]$arg1,[string]$arg2)' \
    'Write-Host This is a sample script with parameters $arg1 and $arg2' \
    --parameters 'arg1=somefoo' 'arg2=somebar' --instance-id 2

Run powershell script on a windows VMSS instance with parameters. Script supplied from file.

# script.ps1
#   param(
#       [string]$arg1,
#       [string]$arg2
#   )
#   Write-Host This is a sample script with parameters $arg1 and $arg2

az vmss run-command invoke  --command-id RunPowerShellScript --name win-vm -g my-resource-group \
    --scripts @script.ps1 --parameters "arg1=somefoo" "arg2=somebar" --instance-id 5

Required Parameters

--command-id

The command id.

value from: az vmss run-command list

Optional Parameters

--ids

One or more resource IDs (space-delimited). If provided, no other 'Resource Id' arguments should be specified.

--instance-id

Scale set VM instance id.

--name -n

Scale set name. You can configure the default using az configure --defaults vmss=<name>.

--parameters

Space-separated parameters in the format of '[name=]value'.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--scripts

Space-separated script lines. Use @{file} to load script from a file.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vmss run-command list

Lists all available run commands for a subscription in a location.

az vmss run-command list --location
[--subscription]

Required Parameters

--location -l

Location. Values from: az account list-locations. You can configure the default location using az configure --defaults location=<location>.

Optional Parameters

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az vmss run-command show

Gets specific run command for a subscription in a location.

az vmss run-command show --command-id
--location
[--subscription]

Examples

vmss run-command show (autogenerated)

az vmss run-command show --command-id RunShellScript --location westus2

Required Parameters

--command-id

The command id.

value from: az vmss run-command list
--location -l

Location. Values from: az account list-locations. You can configure the default location using az configure --defaults location=<location>.

Optional Parameters

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.