-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateVMSS.ps1
35 lines (23 loc) · 1.18 KB
/
UpdateVMSS.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Param(
[string]$resourceGroupName,
[string]$vmssName,
[string]$newversion
)
$rg = Get-AzureRmResourceGroup -Name $resourceGroupName
$vmss = $rg | Get-AzureRmVmss -VMScaleSetName $vmssName
$vmss.virtualMachineProfile.storageProfile.imageReference.version = $newversion
$rg | Update-AzureRmVmss -Name $vmssName -VirtualMachineScaleSet $vmss
$instanceIds = ($vmss | Get-AzureRmVmssVM).InstanceId
#Update in odd and even groups
#Odd numbered array indexes
$instanceGroup1 = $instanceIds[(0..($instanceIds.Length - 1) | where {($_ % 2) -ne 0 })]
#even array indexes
$instanceGroup2 = $instanceIds[(0..($instanceIds.Length - 1) | where {($_ % 2) -eq 0 })]
#ANOTHER OPTION: Update the first half of the instances
#first half
#$instanceGroup1 = $instanceIds[0..(($instanceIds.Length/2)-1)]
#second half
#$instanceGroup2 = $instanceIds[($instanceIds.Length/2)..($instanceIds.Length)]
Update-AzureRmVmssInstance -ResourceGroupName $vmss.ResourceGroupName -VMScaleSetName $vmss.Name -InstanceId $instanceGroup1
#Note: Powershell cmdlet automatically waits until completion
Update-AzureRmVmssInstance -ResourceGroupName $vmss.ResourceGroupName -VMScaleSetName $vmss.Name -InstanceId $instanceGroup2