0

Trying to use Azure nodejs SDK and tested virtual machine run command as mentioned in Get StdOut from RunCommand using Azure VM Javascript SDK. Performance of this call is poor. Does user have permissions to change the timeout value for the Virtual Machine run-command?

Any other alternative to send the script.

Sk0000
  • 31
  • 1
  • 1
  • 5

1 Answers1

2

Yes,the performance of "run command" way is not so good,if you get timeout errors using SDK, maybe calling rest APIs directly will be a workaround.

In terms of underlying , while you use SDK to call run command function , it calls this API :

POST https://management.azure.com/subscriptions/<your subscription ID>/resourceGroups/<resource group name>/providers/Microsoft.Compute/virtualMachines/<VM Name>/runCommand?api-version=2018-04-01

Request Headers:
Content-Type: application/json
Authorization: Bearer <access token>

Request Body:
{"commandId":"RunPowerShellScript","script":["<script content>"]}

Once you called it successfully , you will get a 202 response code and in response header , there will be a param "location" whose value is a link and you can get your command running status using it : enter image description here

enter image description here

With this way , you can monitor running status by calling this url instead of waiting for the response for a long time .

Besides "run command" way to run ps script on Azure VMs, there are 3 other ways to do it:

  1. Azure VM custom script extension
  2. Remote PowerShell
  3. Azure Automation DSC

This blog described them well, you can choose one of them based on your requirement.

Hope it helps.

Stanley Gong
  • 11,522
  • 1
  • 8
  • 16
  • Hi ,how's going there ? – Stanley Gong Aug 27 '19 at 11:23
  • Main thing here is one VM is triggering script to all other VM's in Azure Subscription. I guess all the options need some extra configuration and my goal to minimize them. – Sk0000 Aug 29 '19 at 00:39
  • To be specific I have a nodejs app in VM trying to send powershell script to all the VMs in Azure subscription. I tested out the user identity approach provided by Azure where VM assumes the identity and makes the run command call but it is slow. So, currently I am looking into strategy provided in this article - https://social.msdn.microsoft.com/Forums/en-US/8558bc2a-987b-4898-b5b5-059d64842001/virtual-machine-administrator-login?forum=WAVirtualMachinesforWindows. Have a common AD user on all VMs and run node application with that user and make remote calls. – Sk0000 Aug 29 '19 at 00:49