Powershell script to deploy new server role on Azure VM

Sometime when you deploy Azure VM, you also need to install new role on Azure virtual machine on a customer platform. In this article, I will show you how this could be accomplished without login on VM.

Example-

Let’s assume you want to install the IIS server role; even it works for other roles if you need it. I’ve created a generic powershell script with the following content and save this file as Install.ps1

Install-WindowsFeature -name Web-Server -IncludeManagementTools

Now open powershell terminal, but make sure you have installed all necessary AzRM module on your local machine to execute this script and specified your Azure subscription and invoke the powershell command :

Set-AzureRmContext -Subscription XX-XX-5490-dfns-ap435678j8761
Invoke-AzureRmVMRunCommand `        
        -CommandId "RunPowerShellScript" `        
        -ResourceGroupName "demo-group" `       
        -VMName "demo-vm01" `       
        -ScriptPath "C:\PS\InstallIIS.ps1"

After executing this command the IIS role will be installed on the demo-vm01 server without login on your vm. You can use the same methods to install other role too.

Avatar

About Shachindra Yadav

I, Shachindra Yadav, a Cloud Certified, DevOps and technology enthusiastic person, more passionate to learn and write blogs in my free time.

View all posts by Shachindra Yadav →