DEV Community

Josh Duffney
Josh Duffney

Posted on

Creating Availability Sets for Virtual Machines in Azure with PowerShell

Create a Resource Group

$splat = @{
    Name = 'availabilitySet-rg'
    Location = 'CentralUS'
}

New-AzResourceGroup @splat
Enter fullscreen mode Exit fullscreen mode

Create a Managed Availability Set

$splat = @{
    Location = "CentralUS"
    Name = "availabilitySetPractice"
    ResourceGroupName = "availabilitySet-rg"
    Sku = "aligned"
    PlatformFaultDomainCount = 2
    PlatformUpdateDomainCount = 2
}

New-AzAvailabilitySet @splat
Enter fullscreen mode Exit fullscreen mode

Important notes:

  • SKU aligned means it uses managed disk.
  • Fault Domain max is 3 (currently & depends on region)
  • Update Domain max is 20 (currently)
  • Availability sets are under a 99.95% Azure SLA.

Create Virtual Machines in an Availability Set

$cred = Get-Credential

1..2 | ForEach-Object -Parallel {
    New-AzVm `
        -ResourceGroupName "availabilitySet-rg" `
        -Name "myVM$_" `
        -Location "CentralUS" `
        -VirtualNetworkName "vNet" `
        -SubnetName "Subnet" `
        -SecurityGroupName "NSG" `
        -PublicIpAddressName "publicIpAddress$_" `
        -AvailabilitySetName "availabilitySetPractice" `
        -Credential $using:cred `
}
Enter fullscreen mode Exit fullscreen mode

Delete Resources Clean-up

Remove-AzResourceGroup -Name 'availabilitySet-rg'
Enter fullscreen mode Exit fullscreen mode

Sources

Tutorial: Create and deploy highly available virtual machines with Azure PowerShell

Manage the availability of Windows virtual machines in Azure

Top comments (0)