-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUpdateVMSSwithNewLB.ps1
22 lines (17 loc) · 1.15 KB
/
UpdateVMSSwithNewLB.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#Parameter
$resourceGroupName = "<resourceGroupName>" # ResourceGroup Name of VMSS & LB
$vmssName = "<VMScalesetName>" #VMSS Name
$newLBName = "<LoadBalancerNama>" #LBName
#Get New LoadBalancer Infomation
$LB = Get-AzureRmLoadBalancer -ResourceGroupName $resourceGroupName -Name $newLBName
$LB.BackendAddressPools[0].Id
#Update VMSS Network Config
$targetVmss = Get-AzureRmVmss -ResourceGroupName $resourceGroupName -VMScaleSetName $vmssName
$oldConfig = $targetVmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0]
$newvmssipconfig = New-AzureRmVmssIpConfig -Name $oldConfig.Name`
-LoadBalancerBackendAddressPoolsId $LB.BackendAddressPools[0].Id `
-SubnetId $oldConfig.Subnet.Id
$targetVmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0] = $newvmssipconfig
Update-AzureRmVmss -ResourceGroupName $resourceGroupName -VMScaleSetName $vmssName -VirtualMachineScaleSet $targetVmss
#Manual Upgrade for each instances
Get-AzureRmVmssVM -ResourceGroupName $resourceGroupName -Name $vmssName | Update-AzureRmVmssInstance -ResourceGroupName $resourceGroupName -VMScaleSetName $vmssName