az vm run-command

Commands

az vm run-command create

The operation to create the run command.

az vm run-command delete

The operation to delete the run command.

az vm run-command invoke

Execute a specific run command on a vm.

az vm run-command list

List run commands from a VM or a location.

az vm run-command show

Get specific run command.

az vm run-command update

The operation to update the run command.

az vm run-command wait

Place the CLI in a waiting state until a condition of the res virtual-machine-run-command is met.

az vm run-command create

The operation to create the run command.

az vm run-command create --name
                         --resource-group
                         --vm-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 a run command.

az vm run-command create --resource-group "myResourceGroup" --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" --vm-name "myVM"

Required Parameters

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

--vm-name

The name of the virtual machine.

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

Specify the Azure storage blob where 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.

--output-blob-uri

Specify the Azure storage blob where script output stream 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 vm run-command delete

The operation to delete the run command.

az vm run-command delete --name
                         [--ids]
                         [--no-wait]
                         [--resource-group]
                         [--vm-name]
                         [--yes]

Examples

Delete a run command.

az vm run-command delete --resource-group "myResourceGroup" --run-command-name "myRunCommand" --vm-name "myVM"

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.

--no-wait

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

--resource-group -g

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

--vm-name

The name of the virtual machine.

--yes -y

Do not prompt for confirmation.

az vm run-command invoke

Execute a specific run command on a vm.

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

az vm run-command invoke --command-id
                         [--ids]
                         [--name]
                         [--no-wait]
                         [--parameters]
                         [--resource-group]
                         [--scripts]

Examples

Install nginx on a linux VM.

az vm run-command invoke -g MyResourceGroup -n MyVm --command-id RunShellScript --scripts "sudo apt-get update && sudo apt-get install -y nginx"

Run shell command on a linux VM with parameters.

az vm run-command invoke -g MyResourceGroup -n MyVm --command-id RunShellScript --scripts 'echo $1 $2' --parameters hello world

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

az vm 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'

Run powershell script on a windows VM 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 vm run-command invoke  --command-id RunPowerShellScript --name win-vm -g my-resource-group \
    --scripts @script.ps1 --parameters "arg1=somefoo" "arg2=somebar"

Required Parameters

--command-id

The command id.

value from: az vm 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.

--name -n

The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>.

--no-wait

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

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

az vm run-command list

List run commands from a VM or a location.

You can specify "--resource-group" and "--vm-name" to get all run commands of a virtual machine. Or you can specify "--location" to list all available run commands for a subscription in a location.

az vm run-command list [--expand]
                       [--location]
                       [--resource-group]
                       [--vm-name]

Examples

List run commands in a virtual machine.

az vm run-command list --resource-group "myResourceGroup" --vm-name "myVM"

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

az vm run-command list --location "SoutheastAsia"

Optional Parameters

--expand

The expand expression to apply on the operation.

--location -l

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

--resource-group -g

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

--vm-name

The name of the virtual machine.

az vm run-command show

Get specific run command.

You can specify "--resource-group", "--run-command-name" and "--vm-name" to get run command in a virtual machine. Or you can specify "--command-id" and "--location" to get run command for a subscription in a location.

az vm run-command show [--command-id]
                       [--expand]
                       [--ids]
                       [--instance-view]
                       [--location]
                       [--name]
                       [--resource-group]
                       [--vm-name]

Examples

Get the run commands in a virtual machine.

az vm run-command show --resource-group "myResourceGroup" --run-command-name "myRunCommand" --vm-name "myVM"

Get specific run command for a subscription in a location.

az vm run-command show --command-id "RunPowerShellScript" --location "SoutheastAsia"

Optional Parameters

--command-id

The command id.

--expand

The expand expression to apply on the operation.

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

The instance view of a run command.

--location -l

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

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

--vm-name

The name of the virtual machine.

az vm run-command update

The operation to update the run command.

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

Examples

Update a run command.

az vm run-command update --resource-group "myResourceGroup" --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" --vm-name "myVM"

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

Specify the Azure storage blob where 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.

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

--output-blob-uri

Specify the Azure storage blob where script output stream 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.

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

--vm-name

The name of the virtual machine.

az vm run-command wait

Place the CLI in a waiting state until a condition of the res virtual-machine-run-command is met.

az vm run-command wait [--command-id]
                       [--created]
                       [--custom]
                       [--deleted]
                       [--exists]
                       [--expand]
                       [--ids]
                       [--instance-view]
                       [--interval]
                       [--location]
                       [--name]
                       [--resource-group]
                       [--timeout]
                       [--updated]
                       [--vm-name]

Optional Parameters

--command-id

The command id.

--created

Wait until created with 'provisioningState' at 'Succeeded'.

--custom

Wait until the condition satisfies a custom JMESPath query. E.g. provisioningState!='InProgress', instanceView.statuses[?code=='PowerState/running'].

--deleted

Wait until deleted.

--exists

Wait until the resource exists.

--expand

The expand expression to apply on the operation.

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

The instance view of a run command.

--interval

Polling interval in seconds.

default value: 30
--location -l

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

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

--timeout

Maximum wait in seconds.

default value: 3600
--updated

Wait until updated with provisioningState at 'Succeeded'.

--vm-name

The name of the virtual machine.