Sometimes, it can be helpful to run a command in a Virtual Machine located on Azure in order to remediate a Virtual Machine that doesn’t have the RDP port open. To perform this task, you must use the “Run Command” feature.
How does it work?
Run Command uses the VM agent to let you run a script inside this virtual machine. This can be helpful for instance when you need to create a local admin account even if you don’t have access to the Virtual Machine.
First, you must start the VM in order to perform this task. Then, go to the Virtual Machine and click “Run Command”:
As you can notice, there is a list of the available commands to run on the VM. In my case, I will use the “RunPowerShellScript” command. Here, you can copy/paste your script but be careful because scripts that prompt for information (interactive mode) are not supported.
$Password= ConvertTo-SecureString “P4ssword12345” -AsPlainText -Force
New-LocalUser “GET-CMD” -Password $Password -FullName “GET-CMD” -Description “GET-CMD”
Add-LocalGroupMember -Group “Administrators” -Member “GET-CMD”
Now, run the script and check the output:
Done! The account has been created and added to the Administrators local group.
Thanks for reading! You can follow me on Twitter @PrigentNico