az vmss run-command

Commands

az vmss run-command create

The operation to Create the VMSS VM run command.

az vmss run-command delete

The operation to delete the run command.

az vmss run-command invoke

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

az vmss run-command list

The operation to get all run commands of an instance in Virtual Machine Scaleset.

az vmss run-command show

The operation to get the VMSS run command.

az vmss run-command update

The operation to update the VMSS run command.

az vmss run-command create

The operation to Create the VMSS VM run command.

az vmss run-command create --instance-id
                           --name
                           --resource-group
                           --vmss-name
                           [--async-execution {false, true}]
                           [--command-id]
                           [--error-blob-uri]
                           [--location]
                           [--no-wait]
                           [--output-blob-uri]
                           [--parameters]
                           [--protected-parameters]
                           [--run-as-password]
                           [--run-as-user]
                           [--script]
                           [--script-uri]
                           [--tags]
                           [--timeout-in-seconds]

Examples

Create VMSS run command.

az vmss run-command create --resource-group "myResourceGroup" --instance-id "0" --location "West US" --async-execution false --parameters arg1=param1 arg2=value1 --run-as-password "<runAsPassword>" --run-as-user "user1" --script "Write-Host Hello World!" --timeout-in-seconds 3600 --run-command-name "myRunCommand" --vmss-name "myVMSS"

Required Parameters

--instance-id

The instance ID of the virtual machine.

--name --run-command-name

The name of the virtual machine run command.

--resource-group -g

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

--vmss-name

The name of the VM scale set.

Optional Parameters

--async-execution

Optional. If set to true, provisioning will complete as soon as the script starts and will not wait for script to complete.

accepted values: false, true
--command-id

Specify a commandId of predefined built-in script.

--error-blob-uri

Uri (without SAS) to an append blob where the script error stream will be uploaded.

--location -l

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

--no-wait

Do not wait for the long-running operation to finish.

default value: False
--output-blob-uri

Uri (without SAS) to an append blob where the script output will be uploaded.

--parameters

The parameters used by the script.

--protected-parameters

The parameters used by the script.

--run-as-password

Password if needed for using run-as-user parameter. It will be encrypted and not logged.

--run-as-user

By default script process runs under system/root user. Specify custom user to host the process.

--script

Specify the script content to be executed on the VM.

--script-uri

Specify the script download location.

--tags

Space-separated tags: key[=value] [key[=value] ...]. Use "" to clear existing tags.

--timeout-in-seconds

The timeout in seconds to execute the run command.

az vmss run-command delete

The operation to delete the run command.

az vmss run-command delete --name
                           [--ids]
                           [--instance-id]
                           [--no-wait]
                           [--resource-group]
                           [--subscription]
                           [--vmss-name]
                           [--yes]

Examples

The operation to delete the VMSS run command..

az vmss run-command delete --resource-group "myResourceGroup" --instance-id "0" --run-command-name "myRunCommand" --vmss-name "myVMSS"

Required Parameters

--name --run-command-name

The name of the virtual machine run command.

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

--instance-id

The instance ID of the virtual machine.

--no-wait

Do not wait for the long-running operation to finish.

default value: False
--resource-group -g

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

--subscription

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

--vmss-name

The name of the VM scale set.

--yes -y

Do not prompt for confirmation.

default value: False

az vmss run-command invoke

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

az vmss run-command show returns helpful information on each run-command. Discover Run command-id's via az vmss run-command list.

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). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

--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

The operation to get all run commands of an instance in Virtual Machine Scaleset.

az vmss run-command list --instance-id
                         --resource-group
                         --vmss-name
                         [--expand]

Examples

List run commands in Vmss instance.

az vmss run-command list --resource-group "myResourceGroup" --vmss-name "myVMSS" --instance-id "0"

Required Parameters

--instance-id

The instance ID of the virtual machine.

--resource-group -g

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

--vmss-name

The name of the VM scale set.

Optional Parameters

--expand

The expand expression to apply on the operation.

az vmss run-command show

The operation to get the VMSS run command.

az vmss run-command show --name
                         [--ids]
                         [--instance-id]
                         [--instance-view]
                         [--resource-group]
                         [--subscription]
                         [--vmss-name]

Examples

Get VMSS run commands.

az vmss run-command show --instance-id "0" --resource-group "myResourceGroup" --run-command-name "myRunCommand" --vmss-name "myVMSS"

Required Parameters

--name --run-command-name

The name of the virtual machine run command.

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

--instance-id

The instance ID of the virtual machine.

--instance-view

The instance view of a run command.

default value: False
--resource-group -g

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

--subscription

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

--vmss-name

The name of the VM scale set.

az vmss run-command update

The operation to update the VMSS run command.

az vmss run-command update --name
                           [--async-execution {false, true}]
                           [--command-id]
                           [--error-blob-uri]
                           [--ids]
                           [--instance-id]
                           [--location]
                           [--no-wait]
                           [--output-blob-uri]
                           [--parameters]
                           [--protected-parameters]
                           [--resource-group]
                           [--run-as-password]
                           [--run-as-user]
                           [--script]
                           [--script-uri]
                           [--subscription]
                           [--tags]
                           [--timeout-in-seconds]
                           [--vmss-name]

Examples

Update VMSS run command.

az vmss run-command update --resource-group "myResourceGroup" --instance-id "0" --location "West US" --async-execution false --parameters arg1=param1 arg2=value1 --run-as-password "<runAsPassword>" --run-as-user "user1" --script "Write-Host Hello World!" --timeout-in-seconds 3600 --run-command-name "myRunCommand" --vmss-name "myVMSS"

Required Parameters

--name --run-command-name

The name of the virtual machine run command.

Optional Parameters

--async-execution

Optional. If set to true, provisioning will complete as soon as the script starts and will not wait for script to complete.

accepted values: false, true
--command-id

Specify a commandId of predefined built-in script.

--error-blob-uri

Uri (without SAS) to an append blob where the script error stream will be uploaded.

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

--instance-id

The instance ID of the virtual machine.

--location -l

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

--no-wait

Do not wait for the long-running operation to finish.

default value: False
--output-blob-uri

Uri (without SAS) to an append blob where the script output will be uploaded.

--parameters

The parameters used by the script.

--protected-parameters

The parameters used by the script.

--resource-group -g

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

--run-as-password

Password if needed for using run-as-user parameter. It will be encrypted and not logged.

--run-as-user

By default script process runs under system/root user. Specify custom user to host the process.

--script

Specify the script content to be executed on the VM.

--script-uri

Specify the script download location.

--subscription

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

--tags

Space-separated tags: key[=value] [key[=value] ...]. Use "" to clear existing tags.

--timeout-in-seconds

The timeout in seconds to execute the run command.

--vmss-name

The name of the VM scale set.