Virtual Machines - Run Command

VM でコマンドを実行します。

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/runCommand?api-version=2026-04-01

URI パラメーター

Name / 必須 型 説明
resourceGroupName
path True

string

minLength: 1
maxLength: 90

リソース グループの名前。 名前は大文字と小文字を区別しません。

subscriptionId
path True

string

minLength: 1

ターゲット サブスクリプションの ID。

vmName
path True

string

仮想マシンの名前。

api-version
query True

string

minLength: 1

この操作に使用する API バージョン。

要求本文

Name 必須 型 説明
commandId True

string

定義済みの組み込みスクリプトの commandId を指定します。 Linux で使用可能なコマンド ID は、 https://aka.ms/RunCommandManagedLinux#available-commands、Windows の https://aka.ms/RunCommandManagedWindows#available-commands に記載されています。

parameters

RunCommandInputParameter[]

run コマンド のパラメーター。

script

string[]

Optional. 実行するスクリプト。 この値を指定すると、指定されたスクリプトによってコマンドの既定のスクリプトがオーバーライドされます。

応答

Name 型 説明
200 OK

RunCommandResult

Azureの運用は無事に完了しました。

202 Accepted

リソース操作が受け入れられます。

ヘッダー

  • Location: string
  • Retry-After: integer
Other Status Codes

CloudError

予期しないエラー応答。

セキュリティ

azure_auth

Azure Active Directory OAuth2 フロー。

型: oauth2
フロー: implicit
Authorization URL (承認 URL): https://login.microsoftonline.com/common/oauth2/authorize

スコープ

Name 説明
user_impersonation あなたのユーザー アカウントになりすます

例

VirtualMachineRunCommand

要求のサンプル

POST https://management.azure.com/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/resourceGroups/crptestar98131/providers/Microsoft.Compute/virtualMachines/vm3036/runCommand?api-version=2026-04-01

{
  "commandId": "RunPowerShellScript"
}

応答のサンプル

{
  "value": [
    {
      "code": "ComponentStatus/StdOut/succeeded",
      "level": "Info",
      "displayStatus": "Provisioning succeeded",
      "message": "This is a sample script with parameters value1 value2"
    },
    {
      "code": "ComponentStatus/StdErr/succeeded",
      "level": "Info",
      "displayStatus": "Provisioning succeeded",
      "message": ""
    }
  ]
}
Location: https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/westus/operations/{operationId}&monitor=true&api-version=2026-04-01

定義

Name 説明
ApiError

API エラー。

ApiErrorBase

API エラーベース。

CloudError

コンピューティング サービスからのエラー応答。

InnerError

内部エラーの詳細。

InstanceViewStatus

インスタンス ビューの状態。

RunCommandInput

仮想マシンのパラメーターをキャプチャします。

RunCommandInputParameter

run コマンド パラメーターのプロパティについて説明します。

RunCommandResult
StatusLevelTypes

レベル コード。

ApiError

API エラー。

Name 型 説明
code

string

エラー コード。

details

ApiErrorBase[]

Api エラーの詳細

innererror

InnerError

Api 内部エラー

message

string

エラー メッセージ。

target

string

特定のエラーのターゲット。

ApiErrorBase

API エラーベース。

Name 型 説明
code

string

エラー コード。

message

string

エラー メッセージ。

target

string

特定のエラーのターゲット。

CloudError

コンピューティング サービスからのエラー応答。

Name 型 説明
error

ApiError

API エラー。

InnerError

内部エラーの詳細。

Name 型 説明
errordetail

string

内部エラー メッセージまたは例外ダンプ。

exceptiontype

string

例外の種類。

InstanceViewStatus

インスタンス ビューの状態。

Name 型 説明
code

string

状態コード。

displayStatus

string

状態の短いローカライズ可能なラベル。

level

StatusLevelTypes

レベル コード。

message

string

アラートやエラー メッセージを含む詳細なステータス メッセージ。

time

string (date-time)

状態の時刻。

RunCommandInput

仮想マシンのパラメーターをキャプチャします。

Name 型 説明
commandId

string

定義済みの組み込みスクリプトの commandId を指定します。 Linux で使用可能なコマンド ID は、 https://aka.ms/RunCommandManagedLinux#available-commands、Windows の https://aka.ms/RunCommandManagedWindows#available-commands に記載されています。

parameters

RunCommandInputParameter[]

run コマンド のパラメーター。

script

string[]

Optional. 実行するスクリプト。 この値を指定すると、指定されたスクリプトによってコマンドの既定のスクリプトがオーバーライドされます。

RunCommandInputParameter

run コマンド パラメーターのプロパティについて説明します。

Name 型 説明
name

string

run コマンド のパラメーター名。

value

string

run コマンド パラメーターの値。

RunCommandResult

Name 型 説明
value

InstanceViewStatus[]

コマンド操作の応答を実行します。

StatusLevelTypes

レベル コード。

値 説明
Info
Warning
Error