Skip to content

Instantly share code, notes, and snippets.

@MauricioZa
Last active February 26, 2024 05:09
Show Gist options
  • Select an option

  • Save MauricioZa/a69d1266a32e3cbce55c91024fc5276d to your computer and use it in GitHub Desktop.

Select an option

Save MauricioZa/a69d1266a32e3cbce55c91024fc5276d to your computer and use it in GitHub Desktop.
# ------------------------------
# Prerequisites:
# ------------------------------
# Install the Az module
# Create an Azure Resource Group in the desired subscription
# Create a virtual network in the desired resource group
# Create a subnet in the virtual network above
# -------------------------------------------
# Login to Azure and set the subscription:
# -------------------------------------------
$TenantId = ""
$SubscriptionId = ""
Connect-AzAccount -TenantId $TenantId -SubscriptionId $SubscriptionId
# -------------------------------------------
# Template file
# -------------------------------------------
$TemplateFile = "C:\ARMMichael\VmARMTemplate.json"
# -------------------------------------------
# VM variables
# -------------------------------------------
$resourceGroupName = Read-Host -Prompt "Enter the Resource Group name"
$location = Read-Host -Prompt "Enter the location (i.e. eastus)"
$vmName = Read-Host -Prompt "Enter the VMName"
$vmSize = Read-Host -Prompt "Enter the VM size (i.e. Standard_B1ms)"
$adminUsername = Read-Host -Prompt "Enter the administrator username"
$adminPassword = Read-Host -Prompt "Enter the administrator password" -AsSecureString
# -------------------------------------------
# Select Image
# -------------------------------------------
Write-Host "------------------------------"
Write-Host "Select the image for the VM"
Write-Host "------------------------------"
Write-Host
Write-Host "1. Windows Server 2022 Datacenter"
Write-Host "2. Another image name"
Write-Host "3. Another image name"
Write-Host
$ImageOption = Read-Host "Please select the image option (1, 2, or 3)"
switch ($ImageOption)
{
'1' {$imageReference = "/subscriptions/ef7f6efc-8813-4f2b-b1f0-71406ff5d7b4/resourceGroups/rg-Mike/providers/Microsoft.Compute/images/mikeimage"}
'2' {$imageReference = "<enter here another image reference ID>"}
'3' {$imageReference = "<enter here another image reference ID>"}
}
# -------------------------------------------
# vNet variables
# -------------------------------------------
$vNetResourceGroup = Read-Host -Prompt "Enter the Virtual Network Resource Group Name"
$virtualNetworkName = Read-Host -Prompt "Enter the Virtual Network Name"
$subnetName = Read-Host -Prompt "Enter the subnet name"
# -------------------------------------------
# Deploy the VM
# -------------------------------------------
New-AzResourceGroupDeployment `
-ResourceGroupName $resourceGroupName `
-TemplateUri $TemplateFile `
-vmName $vmName `
-vmSize $vmSize `
-location $location `
-adminUsername $adminUsername `
-adminPassword $adminPassword `
-vNetResourceGroup $vNetResourceGroup `
-virtualNetworkName $virtualNetworkName `
-subnetName $subnetName `
-imageReference $imageReference
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment