az vm run-command
管理虛擬機上的執行命令。
如需詳細資訊,請參閱 https://learn.microsoft.com/azure/virtual-machines/windows/run-command 或 https://learn.microsoft.com/azure/virtual-machines/linux/run-command。
命令
名稱 | Description | 類型 | 狀態 |
---|---|---|---|
az vm run-command create |
要建立執行命令的作業。 |
Core | GA |
az vm run-command delete |
要刪除執行命令的作業。 |
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 |
更新執行命令的作業。 |
Core | GA |
az vm run-command wait |
將 CLI 置於等候狀態,直到符合 res virtual-machine-run-command 的條件為止。 |
Core | GA |
az vm run-command create
要建立執行命令的作業。
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] ...]。使用 「清除現有的標記」。
執行命令的逾時以秒為單位。
全域參數
提高日誌詳細程度以顯示所有調試日誌。
屬性 | 值 |
---|---|
預設值: | False |
顯示此說明訊息並結束。
只顯示錯誤,隱藏警告。
屬性 | 值 |
---|---|
預設值: | False |
Output format.
屬性 | 值 |
---|---|
預設值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/。
訂用帳戶的名稱或標識碼。 您可以使用 az account set -s NAME_OR_ID
來設定預設訂用帳戶。
增加記錄的詳細程度。 針對完整偵錯記錄使用 --debug。
屬性 | 值 |
---|---|
預設值: | False |
az vm run-command delete
要刪除執行命令的作業。
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.
一或多個資源識別碼(以空格分隔)。 它應該是包含 「資源標識碼」自變數所有資訊的完整資源識別碼。 您應該提供 --ids 或其他「資源識別碼」自變數。
屬性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
請勿等候長時間執行的作業完成。
屬性 | 值 |
---|---|
預設值: | False |
資源組名。 您可以使用 az configure --defaults group=<name>
來設定預設群組。
屬性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
訂用帳戶的名稱或標識碼。 您可以使用 az account set -s NAME_OR_ID
來設定預設訂用帳戶。
屬性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
虛擬機器的名稱。
屬性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
請勿提示確認。
屬性 | 值 |
---|---|
預設值: | False |
全域參數
提高日誌詳細程度以顯示所有調試日誌。
屬性 | 值 |
---|---|
預設值: | False |
顯示此說明訊息並結束。
只顯示錯誤,隱藏警告。
屬性 | 值 |
---|---|
預設值: | False |
Output format.
屬性 | 值 |
---|---|
預設值: | 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
探索執行命令標識碼。
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"
必要參數
命令標識碼。
屬性 | 值 |
---|---|
值來源: | 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.
一或多個資源識別碼(以空格分隔)。 它應該是包含 「資源標識碼」自變數所有資訊的完整資源識別碼。 您應該提供 --ids 或其他「資源識別碼」自變數。
屬性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
虛擬機的名稱。 您可以使用 來設定預設值 az configure --defaults vm=<name>
。
屬性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
請勿等候長時間執行的作業完成。
屬性 | 值 |
---|---|
預設值: | False |
以 『[name=]value』 格式的空格分隔參數。
資源組名。 您可以使用 az configure --defaults group=<name>
來設定預設群組。
屬性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
以空格分隔的腳本行。 使用 @{file} 從檔案載入腳本。
訂用帳戶的名稱或標識碼。 您可以使用 az account set -s NAME_OR_ID
來設定預設訂用帳戶。
屬性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
全域參數
提高日誌詳細程度以顯示所有調試日誌。
屬性 | 值 |
---|---|
預設值: | False |
顯示此說明訊息並結束。
只顯示錯誤,隱藏警告。
屬性 | 值 |
---|---|
預設值: | False |
Output format.
屬性 | 值 |
---|---|
預設值: | 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 |
Output format.
屬性 | 值 |
---|---|
預設值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/。
訂用帳戶的名稱或標識碼。 您可以使用 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.
命令標識碼。
一或多個資源識別碼(以空格分隔)。 它應該是包含 「資源標識碼」自變數所有資訊的完整資源識別碼。 您應該提供 --ids 或其他「資源識別碼」自變數。
屬性 | 值 |
---|---|
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 |
訂用帳戶的名稱或標識碼。 您可以使用 az account set -s NAME_OR_ID
來設定預設訂用帳戶。
屬性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
虛擬機器的名稱。
屬性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
全域參數
提高日誌詳細程度以顯示所有調試日誌。
屬性 | 值 |
---|---|
預設值: | False |
顯示此說明訊息並結束。
只顯示錯誤,隱藏警告。
屬性 | 值 |
---|---|
預設值: | False |
Output format.
屬性 | 值 |
---|---|
預設值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/。
增加記錄的詳細程度。 針對完整偵錯記錄使用 --debug。
屬性 | 值 |
---|---|
預設值: | False |
az vm run-command update
更新執行命令的作業。
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。
一或多個資源識別碼(以空格分隔)。 它應該是包含 「資源標識碼」自變數所有資訊的完整資源識別碼。 您應該提供 --ids 或其他「資源識別碼」自變數。
屬性 | 值 |
---|---|
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 上執行的文稿內容。
指定文稿下載位置。
訂用帳戶的名稱或標識碼。 您可以使用 az account set -s NAME_OR_ID
來設定預設訂用帳戶。
屬性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
以空格分隔的標記:key[=value] [key[=value] ...]。使用 「清除現有的標記」。
執行命令的逾時以秒為單位。
虛擬機器的名稱。
屬性 | 值 |
---|---|
Parameter group: | Resource Id Arguments |
全域參數
提高日誌詳細程度以顯示所有調試日誌。
屬性 | 值 |
---|---|
預設值: | False |
顯示此說明訊息並結束。
只顯示錯誤,隱藏警告。
屬性 | 值 |
---|---|
預設值: | False |
Output format.
屬性 | 值 |
---|---|
預設值: | 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.
命令標識碼。
請等候在 '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 |
一或多個資源識別碼(以空格分隔)。 它應該是包含 「資源標識碼」自變數所有資訊的完整資源識別碼。 您應該提供 --ids 或其他「資源識別碼」自變數。
屬性 | 值 |
---|---|
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 |
訂用帳戶的名稱或標識碼。 您可以使用 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 |
Output format.
屬性 | 值 |
---|---|
預設值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/。
增加記錄的詳細程度。 針對完整偵錯記錄使用 --debug。
屬性 | 值 |
---|---|
預設值: | False |