Virtual Machine Scale Set VM Run Commands - Create Or Update
The operation to create or update the VMSS VM run command.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/virtualMachines/{instanceId}/runCommands/{runCommandName}?api-version=2024-07-01
URI Parameters
Name | In | Required | Type | Description |
---|---|---|---|---|
instance
|
path | True |
string |
The instance ID of the virtual machine. |
resource
|
path | True |
string |
The name of the resource group. |
run
|
path | True |
string |
The name of the virtual machine run command. |
subscription
|
path | True |
string |
Subscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID forms part of the URI for every service call. |
vm
|
path | True |
string |
The name of the VM scale set. |
api-version
|
query | True |
string |
Client Api Version. |
Request Body
Media Types: "application/json", "text/json"
Name | Required | Type | Description |
---|---|---|---|
location | True |
string |
Resource location |
properties.asyncExecution |
boolean |
Optional. If set to true, provisioning will complete as soon as the script starts and will not wait for script to complete. |
|
properties.errorBlobManagedIdentity |
User-assigned managed identity that has access to errorBlobUri storage blob. Use an empty object in case of system-assigned identity. Make sure managed identity has been given access to blob's container with 'Storage Blob Data Contributor' role assignment. In case of user-assigned identity, make sure you add it under VM's identity. For more info on managed identity and Run Command, refer https://aka.ms/ManagedIdentity and https://aka.ms/RunCommandManaged |
||
properties.errorBlobUri |
string |
Specifies the Azure storage blob where script error stream will be uploaded. Use a SAS URI with read, append, create, write access OR use managed identity to provide the VM access to the blob. Refer errorBlobManagedIdentity parameter. |
|
properties.outputBlobManagedIdentity |
User-assigned managed identity that has access to outputBlobUri storage blob. Use an empty object in case of system-assigned identity. Make sure managed identity has been given access to blob's container with 'Storage Blob Data Contributor' role assignment. In case of user-assigned identity, make sure you add it under VM's identity. For more info on managed identity and Run Command, refer https://aka.ms/ManagedIdentity and https://aka.ms/RunCommandManaged |
||
properties.outputBlobUri |
string |
Specifies the Azure storage blob where script output stream will be uploaded. Use a SAS URI with read, append, create, write access OR use managed identity to provide the VM access to the blob. Refer outputBlobManagedIdentity parameter. |
|
properties.parameters |
The parameters used by the script. |
||
properties.protectedParameters |
The parameters used by the script. |
||
properties.runAsPassword |
string |
Specifies the user account password on the VM when executing the run command. |
|
properties.runAsUser |
string |
Specifies the user account on the VM when executing the run command. |
|
properties.source |
The source of the run command script. |
||
properties.timeoutInSeconds |
integer |
The timeout in seconds to execute the run command. |
|
properties.treatFailureAsDeploymentFailure |
boolean |
Optional. If set to true, any failure in the script will fail the deployment and ProvisioningState will be marked as Failed. If set to false, ProvisioningState would only reflect whether the run command was run or not by the extensions platform, it would not indicate whether script failed in case of script failures. See instance view of run command in case of script failures to see executionMessage, output, error: https://aka.ms/runcommandmanaged#get-execution-status-and-results |
|
tags |
object |
Resource tags |
Responses
Name | Type | Description |
---|---|---|
200 OK |
OK Media Types: "application/json", "text/json" |
|
201 Created |
Created Media Types: "application/json", "text/json" |
|
Other Status Codes |
Error response describing why the operation failed. 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
Create VirtualMachineScaleSet VM run command.
Sample request
PUT https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/myvmScaleSet/virtualMachines/0/runCommands/myRunCommand?api-version=2024-07-01
{
"location": "West US",
"properties": {
"source": {
"scriptUri": "https://mystorageaccount.blob.core.windows.net/scriptcontainer/MyScript.ps1",
"scriptUriManagedIdentity": {
"objectId": "4231e4d2-33e4-4e23-96b2-17888afa6072"
}
},
"parameters": [
{
"name": "param1",
"value": "value1"
},
{
"name": "param2",
"value": "value2"
}
],
"asyncExecution": false,
"treatFailureAsDeploymentFailure": true,
"runAsUser": "user1",
"runAsPassword": "<runAsPassword>",
"timeoutInSeconds": 3600,
"outputBlobUri": "https://mystorageaccount.blob.core.windows.net/myscriptoutputcontainer/MyScriptoutput.txt",
"errorBlobUri": "https://mystorageaccount.blob.core.windows.net/mycontainer/MyScriptError.txt",
"outputBlobManagedIdentity": {
"clientId": "22d35efb-0c99-4041-8c5b-6d24db33a69a"
},
"errorBlobManagedIdentity": {}
}
}
Sample response
{
"name": "myRunCommand",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/myvmScaleSet/virtualMachines/0/runCommands/myRunCommand",
"type": "Microsoft.Compute/virtualMachineScaleSets/virtualMachines/runCommands",
"location": "westus",
"properties": {
"source": {
"scriptUri": "https://mystorageaccount.blob.core.windows.net/scriptcontainer/MyScript.ps1"
},
"parameters": [
{
"name": "param1",
"value": "value1"
},
{
"name": "param2",
"value": "value2"
}
],
"asyncExecution": false,
"treatFailureAsDeploymentFailure": true,
"runAsUser": "user1",
"timeoutInSeconds": 3600,
"provisioningState": "Succeeded",
"outputBlobUri": "https://mystorageaccount.blob.core.windows.net/myscriptoutputcontainer/MyScriptoutput.txt",
"errorBlobUri": "https://mystorageaccount.blob.core.windows.net/mycontainer/MyScriptError.txt"
}
}
{
"name": "myRunCommand",
"id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/myvmScaleSet/virtualMachines/0/runCommands/myRunCommand",
"type": "Microsoft.Compute/virtualMachineScaleSets/virtualMachines/runCommands",
"location": "westus",
"properties": {
"source": {
"scriptUri": "https://mystorageaccount.blob.core.windows.net/scriptcontainer/MyScript.ps1"
},
"parameters": [
{
"name": "param1",
"value": "value1"
},
{
"name": "param2",
"value": "value2"
}
],
"asyncExecution": false,
"treatFailureAsDeploymentFailure": true,
"runAsUser": "user1",
"timeoutInSeconds": 3600,
"provisioningState": "Creating",
"outputBlobUri": "https://mystorageaccount.blob.core.windows.net/myscriptoutputcontainer/MyScriptoutput.txt",
"errorBlobUri": "https://mystorageaccount.blob.core.windows.net/mycontainer/MyScriptError.txt"
}
}
Definitions
Name | Description |
---|---|
Api |
Api error. |
Api |
Api error base. |
Cloud |
An error response from the Compute service. |
Execution |
Script execution status. |
Inner |
Inner error details. |
Instance |
Instance view status. |
Run |
Describes the properties of a run command parameter. |
Run |
Contains clientId or objectId (use only one, not both) of a user-assigned managed identity that has access to storage blob used in Run Command. Use an empty RunCommandManagedIdentity object in case of system-assigned identity. Make sure the Azure storage blob exists in case of scriptUri, and managed identity has been given access to blob's container with 'Storage Blob Data Reader' role assignment with scriptUri blob and 'Storage Blob Data Contributor' for Append blobs(outputBlobUri, errorBlobUri). In case of user assigned identity, make sure you add it under VM's identity. For more info on managed identity and Run Command, refer https://aka.ms/ManagedIdentity and https://aka.ms/RunCommandManaged. |
Status |
The level code. |
Virtual |
Describes a Virtual Machine run command. |
Virtual |
The instance view of a virtual machine run command. |
Virtual |
Describes the script sources for run command. Use only one of script, scriptUri, commandId. |
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. |
CloudError
An error response from the Compute service.
Name | Type | Description |
---|---|---|
error |
Api error. |
ExecutionState
Script execution status.
Name | Type | Description |
---|---|---|
Canceled |
string |
|
Failed |
string |
|
Pending |
string |
|
Running |
string |
|
Succeeded |
string |
|
TimedOut |
string |
|
Unknown |
string |
InnerError
Inner error details.
Name | Type | Description |
---|---|---|
errordetail |
string |
The internal error message or exception dump. |
exceptiontype |
string |
The exception type. |
InstanceViewStatus
Instance view status.
Name | Type | Description |
---|---|---|
code |
string |
The status code. |
displayStatus |
string |
The short localizable label for the status. |
level |
The level code. |
|
message |
string |
The detailed status message, including for alerts and error messages. |
time |
string |
The time of the status. |
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. |
RunCommandManagedIdentity
Contains clientId or objectId (use only one, not both) of a user-assigned managed identity that has access to storage blob used in Run Command. Use an empty RunCommandManagedIdentity object in case of system-assigned identity. Make sure the Azure storage blob exists in case of scriptUri, and managed identity has been given access to blob's container with 'Storage Blob Data Reader' role assignment with scriptUri blob and 'Storage Blob Data Contributor' for Append blobs(outputBlobUri, errorBlobUri). In case of user assigned identity, make sure you add it under VM's identity. For more info on managed identity and Run Command, refer https://aka.ms/ManagedIdentity and https://aka.ms/RunCommandManaged.
Name | Type | Description |
---|---|---|
clientId |
string |
Client Id (GUID value) of the user-assigned managed identity. ObjectId should not be used if this is provided. |
objectId |
string |
Object Id (GUID value) of the user-assigned managed identity. ClientId should not be used if this is provided. |
StatusLevelTypes
The level code.
Name | Type | Description |
---|---|---|
Error |
string |
|
Info |
string |
|
Warning |
string |
VirtualMachineRunCommand
Describes a Virtual Machine run command.
Name | Type | Default value | Description |
---|---|---|---|
id |
string |
Resource Id |
|
location |
string |
Resource location |
|
name |
string |
Resource name |
|
properties.asyncExecution |
boolean |
False |
Optional. If set to true, provisioning will complete as soon as the script starts and will not wait for script to complete. |
properties.errorBlobManagedIdentity |
User-assigned managed identity that has access to errorBlobUri storage blob. Use an empty object in case of system-assigned identity. Make sure managed identity has been given access to blob's container with 'Storage Blob Data Contributor' role assignment. In case of user-assigned identity, make sure you add it under VM's identity. For more info on managed identity and Run Command, refer https://aka.ms/ManagedIdentity and https://aka.ms/RunCommandManaged |
||
properties.errorBlobUri |
string |
Specifies the Azure storage blob where script error stream will be uploaded. Use a SAS URI with read, append, create, write access OR use managed identity to provide the VM access to the blob. Refer errorBlobManagedIdentity parameter. |
|
properties.instanceView |
The virtual machine run command instance view. |
||
properties.outputBlobManagedIdentity |
User-assigned managed identity that has access to outputBlobUri storage blob. Use an empty object in case of system-assigned identity. Make sure managed identity has been given access to blob's container with 'Storage Blob Data Contributor' role assignment. In case of user-assigned identity, make sure you add it under VM's identity. For more info on managed identity and Run Command, refer https://aka.ms/ManagedIdentity and https://aka.ms/RunCommandManaged |
||
properties.outputBlobUri |
string |
Specifies the Azure storage blob where script output stream will be uploaded. Use a SAS URI with read, append, create, write access OR use managed identity to provide the VM access to the blob. Refer outputBlobManagedIdentity parameter. |
|
properties.parameters |
The parameters used by the script. |
||
properties.protectedParameters |
The parameters used by the script. |
||
properties.provisioningState |
string |
The provisioning state, which only appears in the response. If treatFailureAsDeploymentFailure set to true, any failure in the script will fail the deployment and ProvisioningState will be marked as Failed. If treatFailureAsDeploymentFailure set to false, ProvisioningState would only reflect whether the run command was run or not by the extensions platform, it would not indicate whether script failed in case of script failures. See instance view of run command in case of script failures to see executionMessage, output, error: https://aka.ms/runcommandmanaged#get-execution-status-and-results |
|
properties.runAsPassword |
string |
Specifies the user account password on the VM when executing the run command. |
|
properties.runAsUser |
string |
Specifies the user account on the VM when executing the run command. |
|
properties.source |
The source of the run command script. |
||
properties.timeoutInSeconds |
integer |
The timeout in seconds to execute the run command. |
|
properties.treatFailureAsDeploymentFailure |
boolean |
False |
Optional. If set to true, any failure in the script will fail the deployment and ProvisioningState will be marked as Failed. If set to false, ProvisioningState would only reflect whether the run command was run or not by the extensions platform, it would not indicate whether script failed in case of script failures. See instance view of run command in case of script failures to see executionMessage, output, error: https://aka.ms/runcommandmanaged#get-execution-status-and-results |
tags |
object |
Resource tags |
|
type |
string |
Resource type |
VirtualMachineRunCommandInstanceView
The instance view of a virtual machine run command.
Name | Type | Description |
---|---|---|
endTime |
string |
Script end time. |
error |
string |
Script error stream. |
executionMessage |
string |
Communicate script configuration errors or execution messages. |
executionState |
Script execution status. |
|
exitCode |
integer |
Exit code returned from script execution. |
output |
string |
Script output stream. |
startTime |
string |
Script start time. |
statuses |
The resource status information. |
VirtualMachineRunCommandScriptSource
Describes the script sources for run command. Use only one of script, scriptUri, commandId.
Name | Type | Description |
---|---|---|
commandId |
string |
Specifies a commandId of predefined built-in script. |
script |
string |
Specifies the script content to be executed on the VM. |
scriptUri |
string |
Specifies the script download location. It can be either SAS URI of an Azure storage blob with read access or public URI. |
scriptUriManagedIdentity |
User-assigned managed identity that has access to scriptUri in case of Azure storage blob. Use an empty object in case of system-assigned identity. Make sure the Azure storage blob exists, and managed identity has been given access to blob's container with 'Storage Blob Data Reader' role assignment. In case of user-assigned identity, make sure you add it under VM's identity. For more info on managed identity and Run Command, refer https://aka.ms/ManagedIdentity and https://aka.ms/RunCommandManaged. |