Azure-docs: Unable to find the page with Rest API for running scripts in Azure VMs

Created on 19 May 2020  Â·  5Comments  Â·  Source: MicrosoftDocs/azure-docs

I am looking for a way to execute scripts on a Virtual Machine using Rest API. But the GitHub reference is redirecting me to page not found error. Kindly help me out.

Source Reference

Issue Link


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri3 cxp product-question triaged virtual-machinesvc

All 5 comments

@dileep12231 Thanks for the question!

The source you are looking at is for this document in actual: Run scripts in your Windows VM

The REST API link leads you to this page: Virtual Machines Run Commands - Run Command

Hope this helps.

@BhargaviAnnadevara-MSFT
I already visited this link but there are no examples such as how we can execute a local powershell script using api. If you can provide some sample that would be helpful

@dileep12231 Sure, you can execute the Run Command API for the desired VM from the Try It feature on the page or from Postman as follows:

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

Body:

{
  "commandId": "RunPowerShellScript",
  "script": [
    "param(",
    "    [string]$arg1,",
    "    [string]$arg2",
    ")",
    "Write-Host This is a sample script with parameters $arg1 $arg2"
  ],
  "parameters": [
    {
      "name": "arg1",
      "value": "Hello"
    },
    {
      "name": "arg2",
      "value": "World"
    }
  ]
}

This should yield 202 as the response if the request is well-formed and accepted.

Note: Make sure to include the Authorization header with your token in case you try it with Postman.

The other ways to run PowerShell scripts in your Windows VM by using Run Command are mentioned here.

Hope this helps.

@BhargaviAnnadevara-MSFT
This helps. Thanks a ton!

@dileep12231 Sure, glad I could help! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paulmarshall picture paulmarshall  Â·  3Comments

JamesDLD picture JamesDLD  Â·  3Comments

jamesgallagher-ie picture jamesgallagher-ie  Â·  3Comments

behnam89 picture behnam89  Â·  3Comments

bityob picture bityob  Â·  3Comments