Virtual Machines Run Commands - Run Command

Run command on the VM.

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

URI Parameters

Name In Required Type Description
subscriptionId
path True
  • string

Subscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID forms part of the URI for every service call.

resourceGroupName
path True
  • string

The name of the resource group.

vmName
path True
  • string

The name of the virtual machine.

api-version
query True
  • string

Client Api Version.

Request Body

Media Types: "application/json", "text/json"

Name Required Type Description
commandId True
  • string

The run command id.

parameters

The run command parameters.

script
  • string[]

Optional. The script to be executed. When this value is given, the given script will override the default script of the command.

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=2017-03-30
{
  "commandId": "ipconfig"
}

Sample Response

{
  "startTime": "2017-06-16T23:01:37.8958419+00:00",
  "endTime": "2017-06-16T23:10:11.2897717+00:00",
  "status": "Succeeded",
  "properties": {
    "output": [
      {
        "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": "#< CLIXML \n<Objs Version=\"1.1.0.1\" xmlns=\"http://schemas.microsoft.com/powershell/2004/04\"><Obj S=\"progress\" RefId=\"0\"><TN RefId=\"0\"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N=\"SourceId\">1</I64><PR N=\"Record\"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S=\"progress\" RefId=\"1\"><TNRef RefId=\"0\" /><MS><I64 N=\"SourceId\">2</I64><PR N=\"Record\"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S=\"progress\" RefId=\"2\"><TNRef RefId=\"0\" /><MS><I64 N=\"SourceId\">3</I64><PR N=\"Record\"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>"
      }
    ]
  },
  "name": "289dbc84-3c84-4a86-9e40-bbd4d61edcaf"
}
""

Definitions

ApiError

Api error.

ApiErrorBase

Api error base.

InnerError

Inner error details.

RunCommandInput

Capture Virtual Machine parameters.

RunCommandInputParameter

Describes the properties of a run command parameter.

RunCommandResult

Run command operation response.

ApiError

Api error.

Name Type Description
code
  • string

The error code.

details

The Api error details

innererror

The Api inner error

message
  • string

The error message.

target
  • string

The target of the particular error.

ApiErrorBase

Api error base.

Name Type Description
code
  • string

The error code.

message
  • string

The error message.

target
  • string

The target of the particular error.

InnerError

Inner error details.

Name Type Description
errordetail
  • string

The internal error message or exception dump.

exceptiontype
  • string

The exception type.

RunCommandInput

Capture Virtual Machine parameters.

Name Type Description
commandId
  • string

The run command id.

parameters

The run command parameters.

script
  • string[]

Optional. The script to be executed. When this value is given, the given script will override the default script of the command.

RunCommandInputParameter

Describes the properties of a run command parameter.

Name Type Description
name
  • string

The run command parameter name.

value
  • string

The run command parameter value.

RunCommandResult

Run command operation response.

Name Type Description
endTime
  • string

End time of the operation

error

Api error

name
  • string

Operation ID

properties.output
  • object

Operation output data (raw JSON)

startTime
  • string

Start time of the operation

status
  • string

Operation status