你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

az vmss run-command

命令

名称 说明 类型 状态
az vmss run-command create

创建 VMSS VM 运行命令的操作。

核心 GA
az vmss run-command delete

用于删除 run 命令的操作。

核心 GA
az vmss run-command invoke

在虚拟机规模集实例上执行特定的运行命令。

核心 GA
az vmss run-command list

用于获取虚拟机规模集中实例的所有运行命令的操作。

核心 GA
az vmss run-command show

用于获取 VMSS 运行命令的操作。

核心 GA
az vmss run-command update

用于更新 VMSS run 命令的操作。

核心 GA

az vmss run-command create

创建 VMSS VM 运行命令的操作。

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]

示例

创建 VMSS 运行命令。

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"

必需参数

--instance-id

虚拟机的实例 ID。

--name --run-command-name

虚拟机运行命令的名称。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--vmss-name

VM 规模集的名称。

可选参数

--async-execution

可选。 如果设置为 true,则脚本启动后,预配将立即完成,并且不会等待脚本完成。

接受的值: false, true
--command-id

指定预定义内置脚本的 commandId。

--error-blob-uri

URI (不含 SAS)到追加 blob,其中将上传脚本错误流。

--location -l

Location。 az account list-locations 中的值。 可以使用 az configure --defaults location=<location> 配置默认位置。

--no-wait

不等待长时间运行的操作完成。

默认值: False
--output-blob-uri

URI(没有 SAS)到将上传脚本输出的追加 blob。

--parameters

脚本使用的参数。

用法:--parameters arg1=XX arg2=XX。

--protected-parameters

脚本使用的参数。

用法:--protected-parameters credentials=somefoo secret=somebar。

--run-as-password

使用运行方式用户参数所需的密码。 它将经过加密且未记录。

--run-as-user

默认情况下,脚本进程在系统/根用户下运行。 指定要托管进程的自定义用户。

--script

指定要在 VM 上执行的脚本内容。

--script-uri

指定脚本下载位置。

--tags

空格分隔标记:key[=value] [key[=value] ...]。使用“”清除现有标记。

--timeout-in-seconds

执行 run 命令的超时(以秒为单位)。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az vmss run-command delete

用于删除 run 命令的操作。

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

示例

用于删除 VMSS run 命令的操作。

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

必需参数

--name --run-command-name

虚拟机运行命令的名称。

可选参数

--ids

一个或多个资源 ID(空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--instance-id

虚拟机的实例 ID。

--no-wait

不等待长时间运行的操作完成。

默认值: False
--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--vmss-name

VM 规模集的名称。

--yes -y

不提示确认。

默认值: False
全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az vmss run-command invoke

在虚拟机规模集实例上执行特定的运行命令。

az vmss run-command show 返回有关每个 run-command 的有用信息。 通过 . 发现 Run command-id。az vmss run-command list

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

示例

在 VMSS 实例上安装 nginx。

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"

在 VMSS 实例上使用参数调用 Run-command。

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

使用 VMSS 实例资源 ID 对所有 VMSS 实例调用命令。 注意:“@-”展开为 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 @-

使用参数在 Windows VMSS 实例上运行 powershell 脚本。 内联提供的脚本。 在 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

使用参数在 Windows VMSS 实例上运行 powershell 脚本。 从文件提供的脚本。

# 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

必需参数

--command-id

命令 ID。

值来自: az vmss run-command list

可选参数

--ids

一个或多个资源 ID(空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--instance-id

规模集 VM 实例 ID。

--name -n

规模集名称。 可以使用 < a0/a0> 配置默认值 az configure --defaults vmss=<name>

--parameters

以“[name=]value”格式分隔的空间分隔参数。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--scripts

空格分隔的脚本行。 使用 @{file} 从文件加载脚本。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az vmss run-command list

用于获取虚拟机规模集中实例的所有运行命令的操作。

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

示例

列出 Vmss 实例中的运行命令。

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

必需参数

--instance-id

虚拟机的实例 ID。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--vmss-name

VM 规模集的名称。

可选参数

--expand

要应用于操作的展开表达式。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az vmss run-command show

用于获取 VMSS 运行命令的操作。

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

示例

获取 VMSS 运行命令。

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

必需参数

--name --run-command-name

虚拟机运行命令的名称。

可选参数

--ids

一个或多个资源 ID(空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--instance-id

虚拟机的实例 ID。

--instance-view

运行命令的实例视图。

默认值: False
--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--vmss-name

VM 规模集的名称。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。

az vmss run-command update

用于更新 VMSS run 命令的操作。

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]

示例

更新 VMSS 运行命令。

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"

必需参数

--name --run-command-name

虚拟机运行命令的名称。

可选参数

--async-execution

可选。 如果设置为 true,则脚本启动后,预配将立即完成,并且不会等待脚本完成。

接受的值: false, true
--command-id

指定预定义内置脚本的 commandId。

--error-blob-uri

URI (不含 SAS)到追加 blob,其中将上传脚本错误流。

--ids

一个或多个资源 ID(空格分隔)。 它应该是包含“资源 ID”参数的所有信息的完整资源 ID。 应提供 --id 或其他“资源 ID”参数。

--instance-id

虚拟机的实例 ID。

--location -l

Location。 az account list-locations 中的值。 可以使用 az configure --defaults location=<location> 配置默认位置。

--no-wait

不等待长时间运行的操作完成。

默认值: False
--output-blob-uri

URI(没有 SAS)到将上传脚本输出的追加 blob。

--parameters

脚本使用的参数。

用法:--parameters arg1=XX arg2=XX。

--protected-parameters

脚本使用的参数。

用法:--protected-parameters credentials=somefoo secret=somebar。

--resource-group -g

资源组的名称。 可以使用 az configure --defaults group=<name> 配置默认组。

--run-as-password

使用运行方式用户参数所需的密码。 它将经过加密且未记录。

--run-as-user

默认情况下,脚本进程在系统/根用户下运行。 指定要托管进程的自定义用户。

--script

指定要在 VM 上执行的脚本内容。

--script-uri

指定脚本下载位置。

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--tags

空格分隔标记:key[=value] [key[=value] ...]。使用“”清除现有标记。

--timeout-in-seconds

执行 run 命令的超时(以秒为单位)。

--vmss-name

VM 规模集的名称。

全局参数
--debug

提高日志记录详细程度以显示所有调试日志。

--help -h

显示此帮助消息并退出。

--only-show-errors

只显示错误,取消显示警告。

--output -o

输出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
默认值: json
--query

JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/

--subscription

订阅的名称或 ID。 可以使用 az account set -s NAME_OR_ID 配置默认订阅。

--verbose

提高日志记录详细程度。 使用 --debug 获取完整的调试日志。