Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
readme.md

readme.md

Create Manage and Modify Azure Virtual Machine Scale Sets (AZ PowerShell)

  1. Create resource group
    New-AzResourceGroup -Name vmssPractice -Location eastus
    
  2. Create a virtual machine scale set
    $params = @{
        ResourceGroupName = 'vmssPractice'
        Location = 'eastus'
        VmScaleSetName = 'vmssScaleSet'
        SubnetName = 'vmssSubnet'
        PublicIpAddressName = 'vmssPublicIpAddress'
        LoadBalancerName = 'vmssLoadBalancer'
        UpgradePolicyMode = 'Automatic'
    }
    
    New-AzVmss @params
    # Enter userName & password when prompted
    
  3. Create & Configure Network Security Group
    $vmss = Get-AzVmss -ResourceGroupName vmssPractice -VMScaleSetName vmssScaleSet
    
    $nsgRuleParams = @{
        Name = 'allowHTTP'
        Protocol = 'Tcp'
        Direction = 'Inbound'
        Priority = 200
        SourceAddressPrefix = '*'
        SourcePortRange = '*'
        DestinationAddressPrefix = '*'
        DestinationPortRange = 80
        Access = 'Allow'
    }
    
    $nsgRule = New-AzNetworkSecurityRuleConfig @nsgRuleParams
    
    $nsgParams = @{
        ResourceGroupName = 'vmssPractice'
        Location = 'eastus'
        Name = 'vmssNSG'
        SecurityRules = $nsgRule
    }
    
    $nsg = New-AzNetworkSecurityGroup @nsgParams
    
  4. Add Network Security Group to Subnet Config
    $vnet = Get-AzVirtualNetwork -ResourceGroupName vmssPractice -Name vmssScaleSet
    
    $subnet = $vnet.Subnets[0]
    
    $subnetConfigParams = @{
        VirtualNetwork = $vnet
        Name = 'vmssSubnet'
        AddressPrefix = $subnet.AddressPrefix
        NetworkSecurityGroup = $nsg
    }
    
    $subnetConfig = Set-AzVirtualNetworkSubnetConfig @subnetConfigParams
    
    Set-AzVirtualNetwork -VirtualNetwork $vnet
    
    Update-AzVmss -ResourceGroupName vmssPractice -Name vmssScaleSet -VirtualMachineScaleSet $vmss
    
  5. Deploy sample application on IIS
    $publicSettings = @{
    "fileUris" = (,"https://raw.githubusercontent.com/Azure-Samples/compute-automation-configurations/master/automate-iis.ps1");
    "commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File automate-iis.ps1"
    }
    
    $vmss = Get-AzVmss -ResourceGroupName vmssPractice -VMScaleSetName vmssScaleSet
    
    $extParams = @{
        VirtualMachineScaleSet = $vmss
        Name = 'CustomScript'
        Publisher = 'Microsoft.Compute'
        Type = 'CustomScriptExtension'
        TypeHandlerVersion = 1.8
        Setting = $publicSettings
    }
    
    Add-AzVmssExtension @extParams
    
    Update-AzVmss -ResourceGroupName vmssPractice -Name vmssScaleSet -VirtualMachineScaleSet $vmss
    
  6. Scale Virtual Machine Set by changing capacity
    $vmss = Get-AzVmss -ResourceGroupName vmssPractice -VMScaleSetName vmssScaleSet
    $vmss.sku.capacity = 3
    Update-AzVmss -ResourceGroupName vmssPractice -Name vmssScaleSet -VirtualMachineScaleSet $vmss
    
  7. Allow RDP to Scale Set Instances
    $nsgRuleParams = @{
        Name = 'allowRDP'
        Protocol = 'Tcp'
        Direction = 'Inbound'
        Priority = 100
        SourceAddressPrefix = '*'
        SourcePortRange = '*'
        DestinationAddressPrefix = '*'
        DestinationPortRange = 3389
        Access = 'Allow'
    }
    
    $nsg | Add-AzNetworkSecurityRuleConfig @nsgRuleParams | Set-AzNetworkSecurityGroup
    

Docs

Create a virtual machine scale set with Azure PowerShell

Manage a virtual machine scale set with Azure PowerShell

You can’t perform that action at this time.