How to use Azure ARM to automate VM creation and install apps/software

Razzi29 336 Reputation points
2023-02-24T01:35:46.1066667+00:00

Hello All, posting this question here hoping for some guidance/help. What is the best way/ method/ approach to accomplish the following within Azure, either ARM, Azure CLI, Powershell?

Create a new Windows Server VM, provison 3 additional disks apart from OS

Joined AD domain then reboot

Install IIS components either before or after machine boots

Create new folders and subfolder on disk drives .. ex F:\webroot\cus

Install/ setup IIS web sites and app pools

Install DotNetRuntime version

Install additional third party software, first one then second then third and so on

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,030 questions
Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

Accepted answer
  1. vipullag-MSFT 26,487 Reputation points Moderator
    2023-02-24T04:39:22.74+00:00

    Hello Razzi_The_Cyclist

    Welcome to Microsoft Q&A Platform, thanks for posting your query here.

    You can accomplish the tasks you mentioned in Azure using ARM, Azure CLI & PowerShell.

    Azure CLI: Using Azure CLI to automate VM creation and software installation in Azure provides a flexible and powerful way to deploy and manage resources. By scripting the virtual machine configuration and associated software packages, you can easily automate the deployment and management of infrastructure across multiple Azure regions or environments.
    Ref: https://learn.microsoft.com/en-us/azure/virtual-machines/windows/quick-create-cli

    1. Create a new virtual machine using the az vm create command in Azure CLI. You can specify the virtual machine's configuration, including the OS disk and additional data disks.
    2. Join the VM to the AD domain using the az vm run-command invoke command in Azure CLI, and reboot the VM to apply the changes.
    3. Install the IIS components using the az vm extension set command in Azure CLI. You can either install IIS components before or after the VM boots, depending on your needs.
    4. Create new folders and subfolders on the data disks using the az vm run-command invoke command in Azure CLI. For example, you can create a new directory named F:\webroot\cus using the following command: az vm run-command invoke -g <resource-group> -n <vm-name> --command-id RunPowerShellScript --scripts "New-Item -ItemType Directory -Path F:\webroot\cus"
    5. Set up IIS web sites and app pools using the appropriate cmdlets in PowerShell. For example, you can create a new app pool named "MyAppPool" using the following command: az vm extension set --resource-group <resource-group> --vm-name <vm-name> --name customScript --publisher Microsoft.Azure.Extensions --version 2.0 --protected-settings '{"commandToExecute":"New-WebAppPool -Name MyAppPool"}'
    6. Install the .NET Runtime version using the appropriate installer or package manager. You can use the az vm run-command invoke command to run a script that installs the .NET Runtime. For example, you can download and install the .NET Runtime version using the following script: Invoke-WebRequest -Uri "https://download.microsoft.com/download/D/0/F/D0F84745-8B93-4656-9EC6-DEF8C52EBE1C/dotnet-runtime-5.0.14-win-x64.exe" -OutFile "dotnet-runtime-5.0.14-win-x64.exe" ; Start-Process -FilePath ".\dotnet-runtime-5.0.14-win-x64.exe" -ArgumentList "/install /quiet"
    7. Install any additional third-party software using the appropriate installer or package manager. You can use the az vm run-command invoke command to run a script that installs the software. For example, you can download and install a software package named "MySoftware" using the following script: Invoke-WebRequest -Uri "https://mysoftware.com/download" -OutFile "mysoftware.exe" ; Start-Process -FilePath ".\mysoftware.exe" -ArgumentList "/install /quiet"

    Azure Resource Manager (ARM): Using ARM templates to automate VM creation and software installation in Azure provides a repeatable and consistent way to deploy and manage resources.
    Create a new ARM template that defines the virtual machine's configuration and specifies the additional disks, joining AD domain, and software to be installed. You can create the ARM template using Azure Portal, Visual Studio, or any other code editor.

    Ref: https://learn.microsoft.com/en-us/azure/virtual-machines/windows/quick-create-template

    1. In the ARM template, add the appropriate configuration settings to create a new Windows Server VM with 3 additional disks apart from OS. This can be achieved by defining the OS disk and additional data disks in the storage profile section of the template.
    2. Define a custom script extension in the ARM template to install IIS components, create new folders and subfolders, and set up IIS web sites and app pools. You can write a PowerShell script to perform these tasks, and use the script extension to apply the script to the VM after it is provisioned.
    3. Define another custom script extension to install the .NET Runtime version and any additional third-party software. You can use a separate PowerShell script to install these software packages, and include the script in the custom script extension section of the ARM template.
    4. Use the ARM template to deploy the virtual machine in Azure. The deployment process will automatically apply the custom script extensions and configure the VM as specified in the template.

    PowerShell: Ref:https://learn.microsoft.com/en-us/azure/devtest-labs/devtest-lab-vm-powershell

    1. Create a new virtual machine using the New-AzVM cmdlet in PowerShell. You can specify the virtual machine's configuration, including the OS disk and additional data disks.
    2. Join the VM to the AD domain using the Add-Computer cmdlet in PowerShell, and reboot the VM to apply the changes.
    3. Install the IIS components using the Install-WindowsFeature cmdlet in PowerShell. You can either install IIS components before or after the VM boots, depending on your needs.
    4. Create new folders and subfolders on the data disks using the New-Item cmdlet in PowerShell. For example, you can create a new directory named F:\webroot\cus using the following command: New-Item -ItemType Directory -Path F:\webroot\cus
    5. Set up IIS web sites and app pools using the appropriate cmdlets in PowerShell. For example, you can create a new app pool named "MyAppPool" using the following command: New-WebAppPool -Name "MyAppPool"
    6. Install the .NET Runtime version using the appropriate installer or package manager in PowerShell. For example, you can download and install the .NET Runtime version using the following command: Invoke-WebRequest -Uri "https://download.microsoft.com/download/D/0/F/D0F84745-8B93-4656-9EC6-DEF8C52EBE1C/dotnet-runtime-5.0.14-win-x64.exe" -OutFile "dotnet-runtime-5.0.14-win-x64.exe" ; Start-Process -FilePath ".\dotnet-runtime-5.0.14-win-x64.exe" -ArgumentList "/install /quiet"
    7. Install any additional third-party software using the appropriate installer or package manager in PowerShell. You can use the Invoke-WebRequest cmdlet to download the software installer from the web and the Start-Process cmdlet to run the installer silently.

    Hope this helps.

    If you need further help on this, tag me in a comment.

    If the suggested response helped you resolve your issue, please 'Accept as answer', so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.