Deploying a Windows VM from PowerShell

In the next demonstration, we are going to create two Windows Server VMs from PowerShell and place them in an Availability Set. To do so, you have to perform the following steps:

  1. First, we need to log in to the Azure account, as follows:
Connect-AzAccount
  1. If necessary, select the right subscription, as follows:
Select-AzSubscription -SubscriptionId "********-****-****-****-***********"
  1. Create a resource group for the Availability Set, as follows:
New-AzResourceGroup -Name PacktVMResourceGroup -Location EastUS
  1. Then, we can create an Availability Set for the VMs, as follows:
New-AzAvailabilitySet `
-Location "EastUS" `
-Name "PacktVMAvailabilitySet" `
-ResourceGroupName PacktVMResourceGroup `
-Sku aligned `
-PlatformFaultDomainCount 2 `
-PlatformUpdateDomainCount 2
  1. We have to set the administrator credentials for the VMs, as follows:
$cred = Get-Credential

  1. We can now create the two VMs inside the Availability Set, as follows:
 for ($i=1; $i -le 2; $i++)
{
New-AzVm `
-ResourceGroupName PacktVMResourceGroup `
-Name "PacktVM$i" `
-Location "East US" `
-VirtualNetworkName "PacktVnet" `
-SubnetName "PacktSubnet" `
-SecurityGroupName "PacktNetworkSecurityGroup" `
-PublicIpAddressName "PacktPublicIpAddress$i" `
-AvailabilitySetName "PacktVMAvailabilitySet" `
-Credential $cred
}

In the last two demonstrations, we created VMs inside an Availability Set from the Azure portal and PowerShell. In the next section, we are going to cover scale sets.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.67.216