Virtual Machines - Run Command
Run command on the VM.
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/runCommand?api-version=2022-08-01
URI Parameters
| Name | In | Required | Type | Description |
|---|---|---|---|---|
|
resource
|
path | True |
|
The name of the resource group. |
|
subscription
|
path | True |
|
Subscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID forms part of the URI for every service call. |
|
vm
|
path | True |
|
The name of the virtual machine. |
|
api-version
|
query | True |
|
Client Api Version. |
Request Body
Media Types: "application/json", "text/json"
| Name | Type | Description |
|---|---|---|
| parameters |
Parameters supplied to the Run command operation. |
Responses
| Name | Type | Description |
|---|---|---|
| 200 OK |
OK Media Types: "application/json", "text/json" |
|
| 202 Accepted |
Accepted Media Types: "application/json", "text/json" |
Security
azure_auth
Azure Active Directory OAuth2 Flow
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
| Name | Description |
|---|---|
| user_impersonation | impersonate your user account |
Examples
VirtualMachineRunCommand
Sample Request
POST https://management.azure.com/subscriptions/24fb23e3-6ba3-41f0-9b6e-e41131d5d61e/resourceGroups/crptestar98131/providers/Microsoft.Compute/virtualMachines/vm3036/runCommand?api-version=2022-08-01
{
"commandId": "RunPowerShellScript"
}
Sample Response
{
"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": ""
}
]
}
Definitions
|
Instance |
Instance view status. |
|
Run |
Parameters supplied to the Run command operation. |
|
Run |
The run command parameters. |
|
Run |
|
|
Status |
The level code. |
InstanceViewStatus
Instance view status.
| Name | Type | Description |
|---|---|---|
| code |
|
The status code. |
| displayStatus |
|
The short localizable label for the status. |
| level |
The level code. |
|
| message |
|
The detailed status message, including for alerts and error messages. |
| time |
|
The time of the status. |
RunCommandInput
Parameters supplied to the Run command operation.
| Name | Type | Description |
|---|---|---|
| commandId |
|
The run command id. |
| parameters |
The run command parameters. |
|
| script |
|
Optional. The script to be executed. When this value is given, the given script will override the default script of the command. |
RunCommandInputParameter
The run command parameters.
| Name | Type | Description |
|---|---|---|
| name |
|
The run command parameter name. |
| value |
|
The run command parameter value. |
RunCommandResult
| Name | Type | Description |
|---|---|---|
| value |
Run command operation response. |
StatusLevelTypes
The level code.
| Name | Type | Description |
|---|---|---|
| Error |
|
|
| Info |
|
|
| Warning |
|