Azure – You can run (predefined) commands from the portal

I just found it but apparently it has been there for few weeks already; you can run predefined command from the Azure portal to the Azure virtual machine.

The predefined commands you can execute are:

  • RunPowerShellScript to executes a PowerShell script; the script must be saved in the virtual machine
  • EnableRemotePS to enable remote PowerShell
  • EnableAdminAccount to checks if the local Administrator account is disabled, and if so enables it
  • IPConfig to shows detailed IP configuration for each adapter bound to TCP/IP
  • RDPSettings to checks registry settings and domain policy settings. Suggests policy actions if machine is part of a domain or modifies the settings to default values
  • ResetAccountPassword  to reset the built-in Administrator account password
  • ResetRDPCert to removes the SSL certificate tied to the RDP listener and restores the RDP listerner security to default. Use this script if you see any issues with the certificate
  • SetRDPPort to set the Remote Desktop communication port (to the default or user specified port number) and enables firewall rule for inbound access to the port



The following restrictions apply when using Run Command:

  • Output is limited to last 4096 bytes
  • The minimum time to run a script is about 20 seconds
  • Scripts run as System on Windows
  • One script at a time may run
  • You cannot cancel a running script
  • The maximum time a script can run is 90 minutes, after which it will time out
  • Outbound connectivity from the VM is required to return the results of the script


From the Azure portal

To use this functionality, logon to your Azure portal ( and reach out the virtual machine you want to run a command


Ensure your virtual machine is running; if not, you have to start if off course.


Then go to your VM’s configuration blade and reach out the Operations section to select Run command


Then you select the command you want to run and click Run. If parameter is need, you will be asked to fill the parameter

image image


Once the command is executed, the portal returns the output of the execution



Using PowerShell

You can also use Azure PowerShell to execute these command, like the following sample

Invoke-AzureRmVMRunCommand -ResourceGroupName ‘<your resource group>’ -Name ‘<your virtual machine>’ -CommandId ‘<the command you want to run – RunPowerShellScript, IPConfig…’ <additional parameters if the command requires additional ones

The below sample use the ‘prodrg’ resource group to execute the command ‘RunPowerShellScript” with the script path as parameter to the virtual machine ‘myvirtualmachine’

Invoke-AzureRmVMRunCommand -ResourceGroupName ‘prodrg’ -Name ‘myvirtualmachine’ -CommandId ‘RunPowerShellScript’ -ScriptPath ‘c:\scripts\myscript.ps1’ -Parameter @{“arg1” = “var1″;”arg2” = “var2”}

Leave a Comment

Your email address will not be published. Required fields are marked *

The reCAPTCHA verification period has expired. Please reload the page.