Skip to content

Instantly share code, notes, and snippets.

@wortho
Forked from nmackenzie/LoadBalancedVM.ps1
Last active August 23, 2022 12:44

Revisions

  1. wortho revised this gist Jan 29, 2016. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion LoadBalancedVM.ps1
    Original file line number Diff line number Diff line change
    @@ -57,10 +57,14 @@ $lbrule3 = New-AzureRmLoadBalancerRuleConfig -Name "NAV" `
    -FrontendIpConfiguration $feIpConfig -BackendAddressPool $beAddressPool `
    -Probe $healthProbe -Protocol Tcp -FrontendPort 7046 -BackendPort 7046 -LoadDistribution SourceIPProtocol

    $lbrule4 = New-AzureRmLoadBalancerRuleConfig -Name "NAVHELP" `
    -FrontendIpConfiguration $feIpConfig -BackendAddressPool $beAddressPool `
    -Probe $healthProbe -Protocol Tcp -FrontendPort 49000 -BackendPort 49000

    $alb = New-AzureRmLoadBalancer -ResourceGroupName $resourceGroupName `
    -Name "ALB" -Location $location -FrontendIpConfiguration $feIpConfig `
    -InboundNatRule $inboundNatRule1,$inboundNatRule2 `
    -LoadBalancingRule ($lbrule1,$lbrule2,$lbrule3) -BackendAddressPool $beAddressPool `
    -LoadBalancingRule ($lbrule1,$lbrule2,$lbrule3,$lbrule4) -BackendAddressPool $beAddressPool `
    -Probe $healthProbe

    $nic1 = New-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName `
  2. wortho revised this gist Jan 29, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions LoadBalancedVM.ps1
    Original file line number Diff line number Diff line change
    @@ -51,11 +51,11 @@ $lbrule1 = New-AzureRmLoadBalancerRuleConfig -Name "HTTP" `

    $lbrule2 = New-AzureRmLoadBalancerRuleConfig -Name "HTTPS" `
    -FrontendIpConfiguration $feIpConfig -BackendAddressPool $beAddressPool `
    -Probe $healthProbe -Protocol Tcp -FrontendPort 443 -BackendPort 443
    -Probe $healthProbe -Protocol Tcp -FrontendPort 443 -BackendPort 443 -LoadDistribution SourceIPProtocol

    $lbrule3 = New-AzureRmLoadBalancerRuleConfig -Name "NAV" `
    -FrontendIpConfiguration $feIpConfig -BackendAddressPool $beAddressPool `
    -Probe $healthProbe -Protocol Tcp -FrontendPort 7046 -BackendPort 7046
    -Probe $healthProbe -Protocol Tcp -FrontendPort 7046 -BackendPort 7046 -LoadDistribution SourceIPProtocol

    $alb = New-AzureRmLoadBalancer -ResourceGroupName $resourceGroupName `
    -Name "ALB" -Location $location -FrontendIpConfiguration $feIpConfig `
  3. wortho revised this gist Jan 29, 2016. 1 changed file with 22 additions and 14 deletions.
    36 changes: 22 additions & 14 deletions LoadBalancedVM.ps1
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,20 @@
    $testName = "lower-case-unique-name"
    $testName = "unique-resource-name"

    $resourceGroupName = $testName
    $location = "westus"
    $location = "northeurope"
    $domainName = $testName
    $subnetName = "Subnet-1"

    $publisher = "MicrosoftWindowsServer"
    $offer = "WindowsServer"
    $sku = "2012-R2-Datacenter"
    $publisher = "MicrosoftDynamicsNAV"
    $offer = "DynamicsNAV"
    $sku = "2016"
    $version = "latest"


    $cred = Get-Credential

    New-AzureRmResourceGroup -Name $resourceGroupName -Location $location

    $vip = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroupName -Name "VIP1" `
    $vip = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroupName -Name "PublicIP1" `
    -Location $location -AllocationMethod Dynamic -DomainNameLabel $domainName


    @@ -43,17 +42,25 @@ $beAddressPool = New-AzureRmLoadBalancerBackendAddressPoolConfig -Name "LBBE"


    $healthProbe = New-AzureRmLoadBalancerProbeConfig -Name "HealthProbe" `
    -RequestPath "HealthProbe.aspx" -Protocol http -Port 80 `
    -RequestPath "Default.aspx" -Protocol http -Port 80 `
    -IntervalInSeconds 15 -ProbeCount 2

    $lbrule = New-AzureRmLoadBalancerRuleConfig -Name "HTTP" `
    $lbrule1 = New-AzureRmLoadBalancerRuleConfig -Name "HTTP" `
    -FrontendIpConfiguration $feIpConfig -BackendAddressPool $beAddressPool `
    -Probe $healthProbe -Protocol Tcp -FrontendPort 80 -BackendPort 80

    $lbrule2 = New-AzureRmLoadBalancerRuleConfig -Name "HTTPS" `
    -FrontendIpConfiguration $feIpConfig -BackendAddressPool $beAddressPool `
    -Probe $healthProbe -Protocol Tcp -FrontendPort 443 -BackendPort 443

    $lbrule3 = New-AzureRmLoadBalancerRuleConfig -Name "NAV" `
    -FrontendIpConfiguration $feIpConfig -BackendAddressPool $beAddressPool `
    -Probe $healthProbe -Protocol Tcp -FrontendPort 7046 -BackendPort 7046

    $alb = New-AzureRmLoadBalancer -ResourceGroupName $resourceGroupName `
    -Name "ALB" -Location $location -FrontendIpConfiguration $feIpConfig `
    -InboundNatRule $inboundNatRule1,$inboundNatRule2 `
    -LoadBalancingRule $lbrule -BackendAddressPool $beAddressPool `
    -LoadBalancingRule ($lbrule1,$lbrule2,$lbrule3) -BackendAddressPool $beAddressPool `
    -Probe $healthProbe

    $nic1 = New-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName `
    @@ -83,7 +90,7 @@ For ($i=0; $i -le 1; $i++) {

    $vmName = "$testName-w$i"

    $vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize "Standard_A1" `
    $vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize "Standard_DS1" `
    -AvailabilitySetId $avSet.Id |

    Set-AzureRmVMOperatingSystem -Windows -ComputerName $vmName `
    @@ -101,11 +108,12 @@ For ($i=0; $i -le 1; $i++) {
    -VM $vmConfig
    }

    $ipAddr = Get-AzureRmPublicIpAddress -ResourceGroupName $resourceGroupName

    (Get-AzureRmPublicIpAddress -ResourceGroupName $resourceGroupName).IpAddress

    $ipAddr.IpAddress
    $ipAddr.DnsSettings.Fqdn

    Get-AzureRmResource -ResourceGroupName $resourceGroupName | Select Name, ResourceType
    Find-AzureRmResource -ResourceGroupNameContains $resourceGroupName | Select Name, ResourceType

    <#
    Remove-AzureRmResourceGroup -Name $resourceGroupName
  4. @nmackenzie nmackenzie created this gist Oct 25, 2015.
    112 changes: 112 additions & 0 deletions LoadBalancedVM.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,112 @@
    $testName = "lower-case-unique-name"

    $resourceGroupName = $testName
    $location = "westus"
    $domainName = $testName
    $subnetName = "Subnet-1"

    $publisher = "MicrosoftWindowsServer"
    $offer = "WindowsServer"
    $sku = "2012-R2-Datacenter"
    $version = "latest"


    $cred = Get-Credential

    New-AzureRmResourceGroup -Name $resourceGroupName -Location $location

    $vip = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroupName -Name "VIP1" `
    -Location $location -AllocationMethod Dynamic -DomainNameLabel $domainName


    $subnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName `
    -AddressPrefix "10.0.64.0/24"

    $vnet = New-AzureRmVirtualNetwork -Name "VNET" `
    -ResourceGroupName $resourceGroupName `
    -Location $location -AddressPrefix "10.0.0.0/16" -Subnet $subnet

    $subnet = Get-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet


    $feIpConfig = New-AzureRmLoadBalancerFrontendIpConfig -Name $testName -PublicIpAddress $vip

    $inboundNatRule1 = New-AzureRmLoadBalancerInboundNatRuleConfig -Name "RDP1" `
    -FrontendIpConfiguration $feIpConfig `
    -Protocol TCP -FrontendPort 3441 -BackendPort 3389

    $inboundNatRule2 = New-AzureRmLoadBalancerInboundNatRuleConfig -Name "RDP2" `
    -FrontendIpConfiguration $feIpConfig `
    -Protocol TCP -FrontendPort 3442 -BackendPort 3389

    $beAddressPool = New-AzureRmLoadBalancerBackendAddressPoolConfig -Name "LBBE"


    $healthProbe = New-AzureRmLoadBalancerProbeConfig -Name "HealthProbe" `
    -RequestPath "HealthProbe.aspx" -Protocol http -Port 80 `
    -IntervalInSeconds 15 -ProbeCount 2

    $lbrule = New-AzureRmLoadBalancerRuleConfig -Name "HTTP" `
    -FrontendIpConfiguration $feIpConfig -BackendAddressPool $beAddressPool `
    -Probe $healthProbe -Protocol Tcp -FrontendPort 80 -BackendPort 80

    $alb = New-AzureRmLoadBalancer -ResourceGroupName $resourceGroupName `
    -Name "ALB" -Location $location -FrontendIpConfiguration $feIpConfig `
    -InboundNatRule $inboundNatRule1,$inboundNatRule2 `
    -LoadBalancingRule $lbrule -BackendAddressPool $beAddressPool `
    -Probe $healthProbe

    $nic1 = New-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName `
    -Name "nic1" -Subnet $subnet -Location $location `
    -LoadBalancerInboundNatRule $alb.InboundNatRules[0] `
    -LoadBalancerBackendAddressPool $alb.BackendAddressPools[0]

    $nic2 = New-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName `
    -Name "nic2" -Subnet $subnet -Location $location `
    -LoadBalancerInboundNatRule $alb.InboundNatRules[1] `
    -LoadBalancerBackendAddressPool $alb.BackendAddressPools[0]


    New-AzureRmAvailabilitySet -ResourceGroupName $resourceGroupName `
    -Name "AVSet" -Location $location

    $avset = Get-AzureRmAvailabilitySet -ResourceGroupName $resourceGroupName -Name "AVSet"

    New-AzureRmStorageAccount -ResourceGroupName $resourceGroupName `
    -Name $testName -Location $location -Type Standard_LRS

    Get-AzureRmStorageAccount -ResourceGroupName $resourceGroupName

    [array]$nics = @($nic1,$nic2)

    For ($i=0; $i -le 1; $i++) {

    $vmName = "$testName-w$i"

    $vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize "Standard_A1" `
    -AvailabilitySetId $avSet.Id |

    Set-AzureRmVMOperatingSystem -Windows -ComputerName $vmName `
    -Credential $cred -ProvisionVMAgent -EnableAutoUpdate |

    Set-AzureRmVMSourceImage -PublisherName $publisher -Offer $offer -Skus $sku `
    -Version $version |

    Set-AzureRmVMOSDisk -Name $vmName -VhdUri "https://$testName.blob.core.windows.net/vhds/$vmName-os.vhd" `
    -Caching ReadWrite -CreateOption fromImage |

    Add-AzureRmVMNetworkInterface -Id $nics[$i].Id

    New-AzureRmVM -ResourceGroupName $resourceGroupName -Location $location `
    -VM $vmConfig
    }


    (Get-AzureRmPublicIpAddress -ResourceGroupName $resourceGroupName).IpAddress


    Get-AzureRmResource -ResourceGroupName $resourceGroupName | Select Name, ResourceType

    <#
    Remove-AzureRmResourceGroup -Name $resourceGroupName
    #>