I often need to run a simple task or retrieve information from an Azure VM. Most of the time I want to do so without creating an RDP or SSH session, exposing a WinRM or SSH port, and in some cases need to do so on a VM that is isolated from the internet.
In the past I have relied on the Azure Virtual Machine Custom Script Extension for these types of operations. The Custom Script extension uses the Azure VM Agent to download and run scripts on a virtual machine. It is useful when needing to perform a VM operation or configuration, however is somewhat heavy weight and has one in particular trait that I have found cumbersome. Once the Custom Script Extension has been added to a VM, it needs to then be removed before another instance can be run. This is not a difficult operation but when running multiple scripts against a VM is less than desirable.
Recently an alternate and more lightweight method for running scripts against Azure VMs has been released; the Azure Virtual Machine Run Command. Using a Run Command, PowerShell or Bash scripts can be run against virtual machines with many of the same benefits as the custom script extension, however multiple instances can be run without the need of any type of clean-up action.
In this document I walk through some steps for using the Azure Virtual Machine Run Command action and also provide some troubleshooting information.