az vm run-command
管理虚拟机上的运行命令。
有关详细信息,请参阅 https://learn.microsoft.com/azure/virtual-machines/windows/run-command 或 https://learn.microsoft.com/azure/virtual-machines/linux/run-command。
命令
名称 | 说明 | 类型 | Status |
---|---|---|---|
az vm run-command create |
用于创建 run 命令的操作。 |
Core | GA |
az vm run-command delete |
用于删除 run 命令的操作。 |
Core | GA |
az vm run-command invoke |
在 VM 上执行特定的运行命令。 |
Core | GA |
az vm run-command list |
列出 VM 或位置的运行命令。 |
Core | GA |
az vm run-command show |
获取特定的运行命令。 |
Core | GA |
az vm run-command update |
用于更新 run 命令的操作。 |
Core | GA |
az vm run-command wait |
将 CLI 置于等待状态,直到满足 res virtual-machine-run-command 的条件。 |
Core | GA |
az vm run-command create
用于创建 run 命令的操作。
az vm run-command create --name --run-command-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]
示例
创建运行命令。
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"
使用将脚本输出流上传到 Azure 存储 Blob(SAS URI)创建运行命令。
az vm run-command create --resource-group "myResourceGroup" --location "West US" --script "Write-Host Hello World!" --run-command-name "myRunCommand" --vm-name "myVM" --output-blob-uri "https://mystorageaccount.blob.core.windows.net/mycontainer/RuncommandOutput.txt?sp=racw&st=2022-10-17T19:02:15Z&se=2022-10-18T03:02:15Z&spr=https&sv=2021-06-08&sr=b&sig=3BxtEasfdasdfasdfdYki9yvYsqc60V0%3D"
必需参数
虚拟机运行命令的名称。
资源组的名称。 可以使用 az configure --defaults group=<name>
配置默认组。
虚拟机的名称。
可选参数
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
Optional. 如果设置为 true,则脚本启动后,预配将立即完成,并且不会等待脚本完成。
属性 | 值 |
---|---|
接受的值: | false, true |
指定预定义内置脚本的 commandId。
指定将上传脚本错误流的 Azure 存储 Blob。
Location.
az account list-locations
中的值。 可以使用 az configure --defaults location=<location>
配置默认位置。
不等待长时间运行的操作完成。
属性 | 值 |
---|---|
默认值: | False |
指定将上传脚本输出流的 Azure 存储 Blob(SAS URI)。
脚本使用的参数。
用法:--parameters arg1=XX arg2=XX。
脚本使用的参数。
用法:--protected-parameters credentials=somefoo secret=somebar。
使用运行方式用户参数所需的密码。 它将经过加密且未记录。
默认情况下,脚本进程在系统/根用户下运行。 指定要托管进程的自定义用户。
指定要在 VM 上执行的脚本内容。
指定脚本下载位置。
空格分隔标记:key[=value] [key[=value] ...]。使用“”清除现有标记。
执行 run 命令的超时(以秒为单位)。
全局参数
提高日志记录详细程度以显示所有调试日志。
属性 | 值 |
---|---|
默认值: | False |
显示此帮助消息并退出。
仅显示错误,禁止显示警告。
属性 | 值 |
---|---|
默认值: | False |
输出格式。
属性 | 值 |
---|---|
默认值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/。
订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID
配置默认订阅。
增加日志记录详细程度。 使用 --debug 获取完整的调试日志。
属性 | 值 |
---|---|
默认值: | False |
az vm run-command delete
用于删除 run 命令的操作。
az vm run-command delete --name --run-command-name
[--ids]
[--no-wait]
[--resource-group]
[--subscription]
[--vm-name]
[--yes]
示例
删除运行命令。
az vm run-command delete --resource-group "myResourceGroup" --run-command-name "myRunCommand" --vm-name "myVM"
必需参数
虚拟机运行命令的名称。
可选参数
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
一个或多个资源 ID(以空格分隔)。 它应该是包含“Resource Id”参数的所有信息的完整资源 ID。 应提供 --ids 或其他“Resource Id”参数。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
不等待长时间运行的操作完成。
属性 | 值 |
---|---|
默认值: | False |
资源组的名称。 可以使用 az configure --defaults group=<name>
配置默认组。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID
配置默认订阅。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
虚拟机的名称。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
不要提示确认。
属性 | 值 |
---|---|
默认值: | False |
全局参数
提高日志记录详细程度以显示所有调试日志。
属性 | 值 |
---|---|
默认值: | False |
显示此帮助消息并退出。
仅显示错误,禁止显示警告。
属性 | 值 |
---|---|
默认值: | False |
输出格式。
属性 | 值 |
---|---|
默认值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/。
增加日志记录详细程度。 使用 --debug 获取完整的调试日志。
属性 | 值 |
---|---|
默认值: | False |
az vm run-command invoke
在 VM 上执行特定的运行命令。
az vm run-command show
返回有关每个 run-command 的有用信息。 通过 az vmss run-command list
发现 Run command-id。
az vm run-command invoke --command-id
[--ids]
[--name]
[--no-wait]
[--parameters]
[--resource-group]
[--scripts]
[--subscription]
示例
在 Linux VM 上安装 nginx。
az vm run-command invoke -g MyResourceGroup -n MyVm --command-id RunShellScript --scripts "sudo apt-get update && sudo apt-get install -y nginx"
在具有参数的 Linux VM 上运行 shell 命令。
az vm run-command invoke -g MyResourceGroup -n MyVm --command-id RunShellScript --scripts 'echo $1 $2' --parameters hello world
使用参数在 Windows VM 上运行 powershell 脚本。 内联提供的脚本。 对 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'
使用参数在 Windows VM 上运行 powershell 脚本。 从文件提供的脚本。
# 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"
必需参数
命令 ID。
属性 | 值 |
---|---|
值来源: | az vm run-command list |
可选参数
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
一个或多个资源 ID(以空格分隔)。 它应该是包含“Resource Id”参数的所有信息的完整资源 ID。 应提供 --ids 或其他“Resource Id”参数。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
虚拟机的名称。 可以使用 < a0/a0> 配置默认值 az configure --defaults vm=<name>
。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
不等待长时间运行的操作完成。
属性 | 值 |
---|---|
默认值: | False |
以“[name=]value”格式分隔的空间分隔参数。
资源组的名称。 可以使用 az configure --defaults group=<name>
配置默认组。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
空格分隔的脚本行。 使用 @{file} 从文件加载脚本。
订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID
配置默认订阅。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
全局参数
提高日志记录详细程度以显示所有调试日志。
属性 | 值 |
---|---|
默认值: | False |
显示此帮助消息并退出。
仅显示错误,禁止显示警告。
属性 | 值 |
---|---|
默认值: | False |
输出格式。
属性 | 值 |
---|---|
默认值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/。
增加日志记录详细程度。 使用 --debug 获取完整的调试日志。
属性 | 值 |
---|---|
默认值: | False |
az vm run-command list
列出 VM 或位置的运行命令。
可以指定“--resource-group”和“--vm-name”来获取虚拟机的所有运行命令。 或者,可以指定“--location”列出某个位置中某个订阅的所有可用运行命令。
az vm run-command list [--expand]
[--location]
[--resource-group]
[--vm-name]
示例
列出虚拟机中的运行命令。
az vm run-command list --resource-group "myResourceGroup" --vm-name "myVM"
列出某个位置中订阅的所有可用运行命令。
az vm run-command list --location "SoutheastAsia"
可选参数
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
要应用于作的展开表达式。
Location.
az account list-locations
中的值。 可以使用 az configure --defaults location=<location>
配置默认位置。
资源组的名称。 可以使用 az configure --defaults group=<name>
配置默认组。
虚拟机的名称。
全局参数
提高日志记录详细程度以显示所有调试日志。
属性 | 值 |
---|---|
默认值: | False |
显示此帮助消息并退出。
仅显示错误,禁止显示警告。
属性 | 值 |
---|---|
默认值: | False |
输出格式。
属性 | 值 |
---|---|
默认值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/。
订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID
配置默认订阅。
增加日志记录详细程度。 使用 --debug 获取完整的调试日志。
属性 | 值 |
---|---|
默认值: | False |
az vm run-command show
获取特定的运行命令。
可以指定“--resource-group”、“--run-command-name”和“--vm-name”以获取虚拟机中的运行命令。 或者,可以指定“--command-id”和“--location”来获取某个位置中的订阅的运行命令。
az vm run-command show [--command-id]
[--ids]
[--instance-view]
[--location]
[--name --run-command-name]
[--resource-group]
[--subscription]
[--vm-name]
示例
获取虚拟机中的运行命令。
az vm run-command show --resource-group "myResourceGroup" --run-command-name "myRunCommand" --vm-name "myVM"
获取某个位置中订阅的特定运行命令。
az vm run-command show --command-id "RunPowerShellScript" --location "SoutheastAsia"
可选参数
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
命令 ID。
一个或多个资源 ID(以空格分隔)。 它应该是包含“Resource Id”参数的所有信息的完整资源 ID。 应提供 --ids 或其他“Resource Id”参数。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
运行命令的实例视图。
属性 | 值 |
---|---|
默认值: | False |
Location.
az account list-locations
中的值。 可以使用 az configure --defaults location=<location>
配置默认位置。
虚拟机运行命令的名称。
资源组的名称。 可以使用 az configure --defaults group=<name>
配置默认组。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID
配置默认订阅。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
虚拟机的名称。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
全局参数
提高日志记录详细程度以显示所有调试日志。
属性 | 值 |
---|---|
默认值: | False |
显示此帮助消息并退出。
仅显示错误,禁止显示警告。
属性 | 值 |
---|---|
默认值: | False |
输出格式。
属性 | 值 |
---|---|
默认值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/。
增加日志记录详细程度。 使用 --debug 获取完整的调试日志。
属性 | 值 |
---|---|
默认值: | False |
az vm run-command update
用于更新 run 命令的操作。
az vm run-command update --name --run-command-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]
[--subscription]
[--tags]
[--timeout-in-seconds]
[--vm-name]
示例
更新运行命令。
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"
使用将脚本输出流上传到 Azure 存储 Blob(SAS URI)更新运行命令。
az vm run-command update --resource-group "myResourceGroup" --location "West US" --script "Write-Host Hello World!" --run-command-name "myRunCommand" --vm-name "myVM" --output-blob-uri "https://mystorageaccount.blob.core.windows.net/mycontainer/RuncommandOutput.txt?sp=racw&st=2022-10-17T19:02:15Z&se=2022-10-18T03:02:15Z&spr=https&sv=2021-06-08&sr=b&sig=3BxtEasfdasdfasdfdYki9yvYsqc60V0%3D"
必需参数
虚拟机运行命令的名称。
可选参数
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
Optional. 如果设置为 true,则脚本启动后,预配将立即完成,并且不会等待脚本完成。
属性 | 值 |
---|---|
接受的值: | false, true |
指定预定义内置脚本的 commandId。
指定将上传脚本错误流的 Azure 存储 Blob。
一个或多个资源 ID(以空格分隔)。 它应该是包含“Resource Id”参数的所有信息的完整资源 ID。 应提供 --ids 或其他“Resource Id”参数。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
Location.
az account list-locations
中的值。 可以使用 az configure --defaults location=<location>
配置默认位置。
不等待长时间运行的操作完成。
属性 | 值 |
---|---|
默认值: | False |
指定将上传脚本输出流的 Azure 存储 Blob(SAS URI)。
脚本使用的参数。
用法:--parameters arg1=XX arg2=XX。
脚本使用的参数。
用法:--protected-parameters credentials=somefoo secret=somebar。
资源组的名称。 可以使用 az configure --defaults group=<name>
配置默认组。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
使用运行方式用户参数所需的密码。 它将经过加密且未记录。
默认情况下,脚本进程在系统/根用户下运行。 指定要托管进程的自定义用户。
指定要在 VM 上执行的脚本内容。
指定脚本下载位置。
订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID
配置默认订阅。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
空格分隔标记:key[=value] [key[=value] ...]。使用“”清除现有标记。
执行 run 命令的超时(以秒为单位)。
虚拟机的名称。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
全局参数
提高日志记录详细程度以显示所有调试日志。
属性 | 值 |
---|---|
默认值: | False |
显示此帮助消息并退出。
仅显示错误,禁止显示警告。
属性 | 值 |
---|---|
默认值: | False |
输出格式。
属性 | 值 |
---|---|
默认值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/。
增加日志记录详细程度。 使用 --debug 获取完整的调试日志。
属性 | 值 |
---|---|
默认值: | False |
az vm run-command wait
将 CLI 置于等待状态,直到满足 res virtual-machine-run-command 的条件。
az vm run-command wait [--command-id]
[--created]
[--custom]
[--deleted]
[--exists]
[--ids]
[--instance-view]
[--interval]
[--location]
[--name --run-command-name]
[--resource-group]
[--subscription]
[--timeout]
[--updated]
[--vm-name]
可选参数
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
命令 ID。
等待在“Succeeded”中使用“provisioningState”创建。
属性 | 值 |
---|---|
Parameter group: | Wait Condition Arguments |
默认值: | False |
等待条件满足自定义 JMESPath 查询。 例如 provisioningState!='InProgress', instanceView.statuses[?code=='PowerState/running']。
属性 | 值 |
---|---|
Parameter group: | Wait Condition Arguments |
等到删除为止。
属性 | 值 |
---|---|
Parameter group: | Wait Condition Arguments |
默认值: | False |
等待资源存在。
属性 | 值 |
---|---|
Parameter group: | Wait Condition Arguments |
默认值: | False |
一个或多个资源 ID(以空格分隔)。 它应该是包含“Resource Id”参数的所有信息的完整资源 ID。 应提供 --ids 或其他“Resource Id”参数。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
运行命令的实例视图。
属性 | 值 |
---|---|
默认值: | False |
轮询间隔(以秒为单位)。
属性 | 值 |
---|---|
Parameter group: | Wait Condition Arguments |
默认值: | 30 |
Location.
az account list-locations
中的值。 可以使用 az configure --defaults location=<location>
配置默认位置。
虚拟机运行命令的名称。
资源组的名称。 可以使用 az configure --defaults group=<name>
配置默认组。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID
配置默认订阅。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
最大等待(以秒为单位)。
属性 | 值 |
---|---|
Parameter group: | Wait Condition Arguments |
默认值: | 3600 |
等到 provisioningState 更新为“Succeeded”。
属性 | 值 |
---|---|
Parameter group: | Wait Condition Arguments |
默认值: | False |
虚拟机的名称。
属性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
全局参数
提高日志记录详细程度以显示所有调试日志。
属性 | 值 |
---|---|
默认值: | False |
显示此帮助消息并退出。
仅显示错误,禁止显示警告。
属性 | 值 |
---|---|
默认值: | False |
输出格式。
属性 | 值 |
---|---|
默认值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/。
增加日志记录详细程度。 使用 --debug 获取完整的调试日志。
属性 | 值 |
---|---|
默认值: | False |