Provision a virtual machine

Below is another simple ps script to quickly deploy a B-sku entry level sandbox grade virtual machine.

The OS hard disk tier will deployed as an SSD and has no encryption configured to any Key Vault. No data disks are attached.

#If you need to get a list of available vm sizes per location:
Get-Azlocation | ft  = uaenorth
Get-AzVMSize -Location "uaenorth"

#set subscription focus
Set-AzContext -SubscriptionName "<TargetSubscription>" 

#provision your bespoke variables:
$rgName = "rg-allen"
$VnetName = "vnet-UAEnorth"
$Location = "uaenorth"
$VMName = "vm08"
$vmNIC = "vm08-NIC"
$credential = Get-Credential

#Collect all the information related to the destination virtual network:
$VirtualNetwork = (Get-AzVirtualNetwork -Name $VnetName -ResourceGroupName $RGName)

#Create a network interface for the vm (this is a dependency)
$nic = New-AzNetworkInterface `
    -ResourceGroupName $RGName `
    -Name "vm08-NIC" `
    -Location $Location `
    -SubnetId $VirtualNetwork.Subnets[0].Id

#Define the variables for your vm
$vmConfig = New-AzVMConfig -VMName $VMName -VMSize "Standard_B2s"

#Provision the remaining VM configuration:
$vmConfig = Set-AzVMOperatingSystem -VM $vmConfig `
    -Windows `
    -ComputerName $VMName `
    -Credential $credential `
    -ProvisionVMAgent `
    -EnableAutoUpdate
$vmConfig = Set-AzVMSourceImage -VM $vmConfig `
    -PublisherName "MicrosoftWindowsServer" `
    -Offer "WindowsServer" `
    -Skus "2022-Datacenter" `
    -Version "latest"

#Attach the previously provisioned network interface:
$vmConfig = Add-AzVMNetworkInterface -VM $vmConfig -Id $nic.Id

#Provision and Deploy your VM
New-AzVM -VM $vmConfig -ResourceGroupName $RGName -Location $Location

User <yourLocalOSUsername>
PD   <yourLocalOSPassword>

3 comments

  1. Hey! I could have sworn I’ve been to this site before but after reading through some of the post I realized it’s new to me. Anyhow, I’m definitely delighted I found it and I’ll be book-marking and checking back often!

Leave a comment

Your email address will not be published. Required fields are marked *