DEV Community

Josh Duffney
Josh Duffney

Posted on

1

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up