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.


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.