How to run a command on Azure Virtual Machine without logging on the VM

Azure Run Command allows to run PowerShell scripts to a running Windows VM without connecting the VM. Azure Run command uses the Azure VM Agent on the VM and will not work if the Azure VM doesn’t have a VM agent installed on it.  for more detailed information, have a look here

Restrictions 

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
  • Scripts that prompt for information (interactive mode) are not supported.
  • 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.

Permission for Run Command 

Azure Run commands needs Contributor permission on Azure VM to run the commands.

How to use Azure Run Command 

Select a running Azure VM > operations > Run Command

Run Command

Run a PowerShell Script ipconfig / all 

Run a Powershell command to check the Admin Account Status 

Run a Powershell command to Enabled Web Server role on a VM 

Cheers!!