Let's say you have a VM and you want to execute some scripts on VM then normally you've to log in or ssh to your VM and then execute a command but there is another way to do it on Microsoft Azure and in this article, let us explore that.
Before doing this we need to have a Virtual Machine ready. if you don't know how to create a Virtual Machine on Azure, You can go through this article.
So let us go through the run command, which we have for our Virtual Machines themselves. It is kind of a VM agent that allows us to run a script inside the Virtual Machine.
To get this, go to your VM overview page and search for the run command option inside the operation.
So over here, you have different options. You can perform many operations like you can execute a power shell script, can disable windows updates and set remote desktop port, etc. So we have a lot of options over here.
Now here I am going to use the option of executing a power shell script. I am going to execute a command which will install IIS(Internet information services) on this VM.
Just to make sure that IIS is not installed on this machine I am going to use the public IP and check if it is installed as my HTTP and HTTPS port is open. As you can see that IIS is not installed on the machine and if it was installed, should be getting the home page for Internet information services. but shows the site can't be reached.
So now go to Run Command again and choose RunPowerShellScript. Now enter the command you like to execute and click on Run. I am going to execute this command.
add-windowsfeature web-server -includeallsubfeature
So this command installs the feature of the webserver, including all of its sub-features. so now it's going to run this power shell script on the remote VM itself. it takes little time to complete the execution and once it is done you will see the following output.
Now, after waiting for some time you can see in the output that it is complete. So if I go to the page again and if I hit on refresh you can see the homepage for Internet information services.
So in this way, I didn't connect my machine using SSH or RDP to execute command but I did it from here itself and it is quite a helpful tool for the VM admins.
Thanks and I believe it is helpful.