az vm run-command

命令

名稱 Description 類型 狀態
az vm run-command create

要建立執行命令的作業。

核心 GA
az vm run-command delete

要刪除執行命令的作業。

核心 GA
az vm run-command invoke

在 VM 上執行特定的執行命令。

核心 GA
az vm run-command list

從 VM 或位置列出執行命令。

核心 GA
az vm run-command show

取得特定的執行命令。

核心 GA
az vm run-command update

更新執行命令的作業。

核心 GA
az vm run-command wait

將 CLI 置於等候狀態,直到符合 res virtual-machine-run-command 的條件為止。

核心 GA

az vm run-command create

要建立執行命令的作業。

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]

範例

建立執行命令。

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"

必要參數

--name --run-command-name

虛擬機器執行命令的名稱。

--resource-group -g

資源組名。 您可以使用 來設定預設群組 az configure --defaults group=<name>

--vm-name

虛擬機器的名稱。

選擇性參數

--async-execution

選擇性。 如果設定為 true,則一開始腳本就會完成布建,且不會等待腳本完成。

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

指定預先定義內建腳本的 commandId。

--error-blob-uri

指定將上傳腳本錯誤資料流程的 Azure 儲存體 Blob。

--location -l

位置。​​ 來自的值: az account list-locations 。 您可以使用 來設定預設位置 az configure --defaults location=<location>

--no-wait

請勿等候長時間執行的作業完成。

預設值: False
--output-blob-uri

指定將上傳腳本輸出資料流程的 Azure 儲存體 Blob(SAS URI)。

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

執行命令的逾時以秒為單位。

全域參數
--debug

增加記錄詳細資訊,以顯示所有偵錯記錄。

--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

--output -o

輸出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
預設值: json
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。

az vm run-command delete

要刪除執行命令的作業。

az vm run-command delete --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"

必要參數

--name --run-command-name

虛擬機器執行命令的名稱。

選擇性參數

--ids

一或多個資源識別碼 (以空格分隔)。 它應該是包含 「資源識別碼」引數所有資訊的完整資源識別碼。 您應該提供 --ids 或其他「資源識別碼」引數。

--no-wait

請勿等候長時間執行的作業完成。

預設值: False
--resource-group -g

資源組名。 您可以使用 來設定預設群組 az configure --defaults group=<name>

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--vm-name

虛擬機器的名稱。

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

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。

az vm run-command invoke

在 VM 上執行特定的執行命令。

az vm run-command show 會傳回每個 run-command 的實用資訊。 透過 探索執行命令識別碼 az vmss run-command list

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 上執行殼層命令。

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"

必要參數

--command-id

命令識別碼。

值來自: az vm run-command list

選擇性參數

--ids

一或多個資源識別碼 (以空格分隔)。 它應該是包含 「資源識別碼」引數所有資訊的完整資源識別碼。 您應該提供 --ids 或其他「資源識別碼」引數。

--name -n

虛擬機器的名稱。 您可以使用 來設定預設值 az configure --defaults vm=<name>

--no-wait

請勿等候長時間執行的作業完成。

預設值: False
--parameters

以 '[name=]value' 格式的空格分隔參數。

--resource-group -g

資源組名。 您可以使用 來設定預設群組 az configure --defaults group=<name>

--scripts

以空格分隔的腳本行。 使用 @{file} 從檔案載入腳本。

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 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

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。

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"

選擇性參數

--expand

要套用至作業的展開運算式。

--location -l

位置。​​ 來自的值: az account list-locations 。 您可以使用 來設定預設位置 az configure --defaults location=<location>

--resource-group -g

資源組名。 您可以使用 來設定預設群組 az configure --defaults group=<name>

--vm-name

虛擬機器的名稱。

全域參數
--debug

增加記錄詳細資訊,以顯示所有偵錯記錄。

--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

--output -o

輸出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
預設值: json
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。

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]
                       [--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"

選擇性參數

--command-id

命令識別碼。

--ids

一或多個資源識別碼 (以空格分隔)。 它應該是包含 「資源識別碼」引數所有資訊的完整資源識別碼。 您應該提供 --ids 或其他「資源識別碼」引數。

--instance-view

執行命令的實例檢視。

預設值: False
--location -l

位置。​​ 來自的值: az account list-locations 。 您可以使用 來設定預設位置 az configure --defaults location=<location>

--name --run-command-name

虛擬機器執行命令的名稱。

--resource-group -g

資源組名。 您可以使用 來設定預設群組 az configure --defaults group=<name>

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--vm-name

虛擬機器的名稱。

全域參數
--debug

增加記錄詳細資訊,以顯示所有偵錯記錄。

--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

--output -o

輸出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
預設值: json
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。

az vm run-command update

更新執行命令的作業。

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]
                         [--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"

必要參數

--name --run-command-name

虛擬機器執行命令的名稱。

選擇性參數

--async-execution

選擇性。 如果設定為 true,則一開始腳本就會完成布建,且不會等待腳本完成。

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

指定預先定義內建腳本的 commandId。

--error-blob-uri

指定將上傳腳本錯誤資料流程的 Azure 儲存體 Blob。

--ids

一或多個資源識別碼 (以空格分隔)。 它應該是包含 「資源識別碼」引數所有資訊的完整資源識別碼。 您應該提供 --ids 或其他「資源識別碼」引數。

--location -l

位置。​​ 來自的值: az account list-locations 。 您可以使用 來設定預設位置 az configure --defaults location=<location>

--no-wait

請勿等候長時間執行的作業完成。

預設值: False
--output-blob-uri

指定將上傳腳本輸出資料流程的 Azure 儲存體 Blob(SAS URI)。

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

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--tags

以空格分隔的標記:key[=value] [key[=value] ...]。使用 「」 清除現有的標記。

--timeout-in-seconds

執行命令的逾時以秒為單位。

--vm-name

虛擬機器的名稱。

全域參數
--debug

增加記錄詳細資訊,以顯示所有偵錯記錄。

--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

--output -o

輸出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
預設值: json
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。

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]
                       [--resource-group]
                       [--subscription]
                       [--timeout]
                       [--updated]
                       [--vm-name]

選擇性參數

--command-id

命令識別碼。

--created

請等候在 'Succeeded' 使用 'provisioningState' 建立。

預設值: False
--custom

等到條件符合自訂 JMESPath 查詢為止。 例如 provisioningState!='InProgress', instanceView.statuses[?code=='PowerState/running']。

--deleted

等到刪除為止。

預設值: False
--exists

等候資源存在。

預設值: False
--ids

一或多個資源識別碼 (以空格分隔)。 它應該是包含 「資源識別碼」引數所有資訊的完整資源識別碼。 您應該提供 --ids 或其他「資源識別碼」引數。

--instance-view

執行命令的實例檢視。

預設值: False
--interval

輪詢間隔以秒為單位。

預設值: 30
--location -l

位置。​​ 來自的值: az account list-locations 。 您可以使用 來設定預設位置 az configure --defaults location=<location>

--name --run-command-name

虛擬機器執行命令的名稱。

--resource-group -g

資源組名。 您可以使用 來設定預設群組 az configure --defaults group=<name>

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--timeout

以秒為單位的等候上限。

預設值: 3600
--updated

等到 provisioningState 更新為 'Succeeded'。

預設值: False
--vm-name

虛擬機器的名稱。

全域參數
--debug

增加記錄詳細資訊,以顯示所有偵錯記錄。

--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

--output -o

輸出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
預設值: json
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。