az vm run-command
Manage run commands on a Virtual Machine.
For more information, see https://docs.microsoft.com/azure/virtual-machines/windows/run-command or https://docs.microsoft.com/azure/virtual-machines/linux/run-command.
Commands
az vm run-command invoke |
Execute a specific run command on a vm. |
az vm run-command list |
Lists all available run commands for a subscription in a location. |
az vm run-command show |
Gets specific run command for a subscription in a location. |
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]
[--parameters]
[--resource-group]
[--scripts]
[--subscription]
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
The command id.
Optional Parameters
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.
The name of the Virtual Machine. You can configure the default using az configure --defaults vm=<name>
.
Space-separated parameters in the format of '[name=]value'.
Name of resource group. You can configure the default group using az configure --defaults group=<name>
.
Space-separated script lines. Use @{file} to load script from a file.
Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID
.
Increase logging verbosity to show all debug logs.
Show this help message and exit.
Only show errors, suppressing warnings.
Output format.
JMESPath query string. See http://jmespath.org/ for more information and examples.
Increase logging verbosity. Use --debug for full debug logs.
az vm run-command list
Lists all available run commands for a subscription in a location.
az vm run-command list --location
[--query-examples]
[--subscription]
Required Parameters
Location. Values from: az account list-locations
. You can configure the default location using az configure --defaults location=<location>
.
Optional Parameters
Recommend JMESPath string for you. You can copy one of the query and paste it after --query parameter within double quotation marks to see the results. You can add one or more positional keywords so that we can give suggestions based on these key words.
Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID
.
Increase logging verbosity to show all debug logs.
Show this help message and exit.
Only show errors, suppressing warnings.
Output format.
JMESPath query string. See http://jmespath.org/ for more information and examples.
Increase logging verbosity. Use --debug for full debug logs.
az vm run-command show
Gets specific run command for a subscription in a location.
az vm run-command show --command-id
--location
[--query-examples]
[--subscription]
Examples
vm run-command show (autogenerated)
az vm run-command show --command-id RunShellScript --location westus2
Required Parameters
The command id.
Location. Values from: az account list-locations
. You can configure the default location using az configure --defaults location=<location>
.
Optional Parameters
Recommend JMESPath string for you. You can copy one of the query and paste it after --query parameter within double quotation marks to see the results. You can add one or more positional keywords so that we can give suggestions based on these key words.
Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID
.
Increase logging verbosity to show all debug logs.
Show this help message and exit.
Only show errors, suppressing warnings.
Output format.
JMESPath query string. See http://jmespath.org/ for more information and examples.
Increase logging verbosity. Use --debug for full debug logs.