Skip to content

Commit 5ccf776

Browse files
authored
Merge pull request #102303 from cynthn/ppg-move
Move into PPG
2 parents 7edb307 + 478b0bf commit 5ccf776

File tree

1 file changed

+101
-8
lines changed

1 file changed

+101
-8
lines changed

articles/virtual-machines/windows/proximity-placement-groups.md

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
---
2-
title: Use proximity placement groups for Windows VMs
3-
description: Learn about creating and using proximity placement groups for Windows virtual machines in Azure.
4-
services: virtual-machines-windows
5-
author: cynthn
6-
manager: gwallace
7-
ms.service: virtual-machines-windows
2+
title: "PowerShell: Use proximity placement groups"
3+
description: Learn about creating and using proximity placement groups using Azure PowerShell.
4+
services: virtual-machines
5+
ms.service: virtual-machines
86

97
ms.topic: article
108
ms.tgt_pltfrm: vm-windows
119
ms.workload: infrastructure-services
12-
ms.date: 10/30/2019
10+
ms.date: 01/27/2020
1311
ms.author: cynthn
14-
12+
#pmcontact: zivr
1513
---
1614

1715
# Deploy VMs to proximity placement groups using PowerShell
@@ -68,13 +66,108 @@ Get-AzProximityPlacementGroup -ResourceId $ppg.Id |
6866
Format-Table -Property VirtualMachines -Wrap
6967
```
7068

69+
### Move an existing VM into a proximity placement group
70+
71+
You can also add an existing VM to a proximity placement group. You need to stop\deallocate the VM first, then update the VM and restart.
72+
73+
```azurepowershell-interactive
74+
$ppg = Get-AzProximityPlacementGroup -ResourceGroupName myPPGResourceGroup -Name myPPG
75+
$vm = Get-AzVM -ResourceGroupName myResourceGroup -Name myVM
76+
Stop-AzVM -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName
77+
Update-AzVM -VM $vm -ResourceGroupName $vm.ResourceGroupName -ProximityPlacementGroupId $ppg.Id
78+
Restart-AzVM -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName
79+
```
80+
81+
### Move an existing VM out of a proximity placement group
82+
83+
To remove a VM from a proximity placement group, you need to stop\deallocate the VM first, then update the VM and restart.
84+
85+
```azurepowershell-interactive
86+
$ppg = Get-AzProximityPlacementGroup -ResourceGroupName myPPGResourceGroup -Name myPPG
87+
$vm = Get-AzVM -ResourceGroupName myResourceGroup -Name myVM
88+
Stop-AzVM -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName
89+
$vm.ProximityPlacementGroupId = ""
90+
Update-AzVM -VM $vm -ResourceGroupName $vm.ResourceGroupName
91+
Restart-AzVM -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName
92+
```
93+
94+
7195
## Availability Sets
7296
You can also create an availability set in your proximity placement group. Use the same `-ProximityPlacementGroup` parameter with the [New-AzAvailabilitySet](/powershell/module/az.compute/new-azavailabilityset) cmdlet to create an availability set and all of the VMs created in the availability set will also be created in the same proximity placement group.
7397

98+
To add or remove an existing availability set to a proximity placement group, you first need to stop all of the VMs in the availability set.
99+
100+
### Move an existing availability set into a proximity placement group
101+
102+
```azurepowershell-interactive
103+
$resourceGroup = "myResourceGroup"
104+
$avSetName = "myAvailabilitySet"
105+
$avSet = Get-AzAvailabilitySet -ResourceGroupName $resourceGroup -Name $avSetName
106+
$vmIds = $avSet.VirtualMachinesReferences
107+
foreach ($vmId in $vmIDs){
108+
$string = $vmID.Id.Split("/")
109+
$vmName = $string[8]
110+
Stop-AzVM -ResourceGroupName $resourceGroup -Name $vmName -Force
111+
}
112+
113+
$ppg = Get-AzProximityPlacementGroup -ResourceGroupName myPPG -Name myPPG
114+
Update-AzAvailabilitySet -AvailabilitySet $avSet -ProximityPlacementGroupId $ppg.Id
115+
foreach ($vmId in $vmIDs){
116+
$string = $vmID.Id.Split("/")
117+
$vmName = $string[8]
118+
Start-AzVM -ResourceGroupName $resourceGroup -Name $vmName
119+
}
120+
```
121+
122+
### Move an existing availability set out of a proximity placement group
123+
124+
```azurepowershell-interactive
125+
$resourceGroup = "myResourceGroup"
126+
$avSetName = "myAvailabilitySet"
127+
$avSet = Get-AzAvailabilitySet -ResourceGroupName $resourceGroup -Name $avSetName
128+
$vmIds = $avSet.VirtualMachinesReferences
129+
foreach ($vmId in $vmIDs){
130+
$string = $vmID.Id.Split("/")
131+
$vmName = $string[8]
132+
Stop-AzVM -ResourceGroupName $resourceGroup -Name $vmName -Force
133+
}
134+
135+
$avSet.ProximityPlacementGroup = ""
136+
Update-AzAvailabilitySet -AvailabilitySet $avSet
137+
foreach ($vmId in $vmIDs){
138+
$string = $vmID.Id.Split("/")
139+
$vmName = $string[8]
140+
Start-AzVM -ResourceGroupName $resourceGroup -Name $vmName
141+
}
142+
```
143+
74144
## Scale sets
75145

76146
You can also create a scale set in your proximity placement group. Use the same `-ProximityPlacementGroup` parameter with [New-AzVmss](https://docs.microsoft.com/powershell/module/az.compute/new-azvmss) to create a scale set and all of the instances will be created in the same proximity placement group.
77147

148+
149+
To add or remove an existing scale set to a proximity placement group, you first need to stop the scale set.
150+
151+
### Move an existing scale set into a proximity placement group
152+
153+
```azurepowershell-interactive
154+
$ppg = Get-AzProximityPlacementGroup -ResourceGroupName myPPG -Name myPPG
155+
$vmss = Get-AzVmss -ResourceGroupName myVMSSResourceGroup -VMScaleSetName myScaleSet
156+
Stop-AzVmss -VMScaleSetName $vmss.Name -ResourceGroupName $vmss.ResourceGroupName
157+
Update-AzVmss -VMScaleSetName $vmss.Name -ResourceGroupName $vmss.ResourceGroupName -ProximityPlacementGroupId $ppg.Id
158+
Restart-AzVmss -VMScaleSetName $vmss.Name -ResourceGroupName $vmss.ResourceGroupName
159+
```
160+
161+
### Move an existing scale set out of a proximity placement group
162+
163+
```azurepowershell-interactive
164+
$vmss = Get-AzVmss -ResourceGroupName myVMSSResourceGroup -VMScaleSetName myScaleSet
165+
Stop-AzVmss -VMScaleSetName $vmss.Name -ResourceGroupName $vmss.ResourceGroupName
166+
$vmss.ProximityPlacementGroup = ""
167+
Update-AzVmss -VirtualMachineScaleSet $vmss -VMScaleSetName $vmss.Name -ResourceGroupName $vmss.ResourceGroupName
168+
Restart-AzVmss -VMScaleSetName $vmss.Name -ResourceGroupName $vmss.ResourceGroupName
169+
```
170+
78171
## Next steps
79172

80173
You can also use the [Azure CLI](../linux/proximity-placement-groups.md) to create proximity placement groups.

0 commit comments

Comments
 (0)