Skip to content

Commit 3d8de2f

Browse files
authored
Merge pull request #108012 from cynthn/public-49791
DH PowerShell - Fixes #49791
2 parents 02909f7 + 038eb6c commit 3d8de2f

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

articles/virtual-machines/windows/dedicated-hosts-portal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This article guides you through how to create an Azure [dedicated host](dedicate
3434

3535
## Add an existing VM
3636

37-
You can add an exiting VM to a dedicated host, but the VM must first be Stop\Deallocated. Before you move a VM to a dedicated host, make sure that the VM configuration is supported:
37+
You can add an existing VM to a dedicated host, but the VM must first be Stop\Deallocated. Before you move a VM to a dedicated host, make sure that the VM configuration is supported:
3838

3939
- The VM size must be in the same size family as the dedicated host. For example, if your dedicated host is DSv3, then the VM size could be Standard_D4s_v3, but it could not be a Standard_A4_v2.
4040
- The VM needs to be located in same region as the dedicated host.

articles/virtual-machines/windows/dedicated-hosts-powershell.md

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ In either case, you are need to provide the fault domain count for your host gro
3333
You can also decide to use both availability zones and fault domains. This example creates a host group in zone 1, with 2 fault domains.
3434

3535

36-
```powershell
36+
```azurepowershell-interactive
3737
$rgName = "myDHResourceGroup"
38-
$location = "East US"
38+
$location = "EastUS"
3939
4040
New-AzResourceGroup -Location $location -Name $rgName
4141
$hostGroup = New-AzHostGroup `
@@ -55,7 +55,7 @@ For more information about the host SKUs and pricing, see [Azure Dedicated Host
5555
If you set a fault domain count for your host group, you will be asked to specify the fault domain for your host. In this example, we set the fault domain for the host to 1.
5656

5757

58-
```powershell
58+
```azurepowershell-interactive
5959
$dHost = New-AzHost `
6060
-HostGroupName $hostGroup.Name `
6161
-Location $location -Name myHost `
@@ -72,7 +72,7 @@ Create a virtual machine on the dedicated host.
7272
If you specified an availability zone when creating your host group, you are required to use the same zone when creating the virtual machine. For this example, because our host group is in zone 1, we need to create the VM in zone 1.
7373

7474

75-
```powershell
75+
```azurepowershell-interactive
7676
$cred = Get-Credential
7777
New-AzVM `
7878
-Credential $cred `
@@ -92,7 +92,7 @@ New-AzVM `
9292

9393
You can check the host health status and how many virtual machines you can still deploy to the host using [GetAzHost](/powershell/module/az.compute/get-azhost) with the `-InstanceView` parameter.
9494

95-
```
95+
```azurepowershell-interactive
9696
Get-AzHost `
9797
-ResourceGroupName $rgName `
9898
-Name myHost `
@@ -161,25 +161,71 @@ Location : eastus
161161
Tags : {}
162162
```
163163

164+
## Add an existing VM
165+
166+
You can add an exiting VM to a dedicated host, but the VM must first be Stop\Deallocated. Before you move a VM to a dedicated host, make sure that the VM configuration is supported:
167+
168+
- The VM size must be in the same size family as the dedicated host. For example, if your dedicated host is DSv3, then the VM size could be Standard_D4s_v3, but it could not be a Standard_A4_v2.
169+
- The VM needs to be located in same region as the dedicated host.
170+
- The VM can't be part of a proximity placement group. Remove the VM from the proximity placement group before moving it to a dedicated host. For more information, see [Move a VM out of a proximity placement group](https://docs.microsoft.com/azure/virtual-machines/windows/proximity-placement-groups#move-an-existing-vm-out-of-a-proximity-placement-group)
171+
- The VM can't be in an availability set.
172+
- If the VM is in an availability zone, it must be the same availability zone as the host group. The availability zone settings for the VM and the host group must match.
173+
174+
Replace the values of the variables with your own information.
175+
176+
```azurepowershell-interactive
177+
$vmRGName = "movetohost"
178+
$vmName = "myVMtoHost"
179+
$dhRGName = "myDHResourceGroup"
180+
$dhGroupName = "myHostGroup"
181+
$dhName = "myHost"
182+
183+
$myDH = Get-AzHost `
184+
-HostGroupName $dhGroupName `
185+
-ResourceGroupName $dhRGName `
186+
-Name $dhName
187+
188+
$myVM = Get-AzVM `
189+
-ResourceGroupName $vmRGName `
190+
-Name $vmName
191+
192+
$myVM.Host = New-Object Microsoft.Azure.Management.Compute.Models.SubResource
193+
194+
$myVM.Host.Id = "$myDH.Id"
195+
196+
Stop-AzVM `
197+
-ResourceGroupName $vmRGName `
198+
-Name $vmName -Force
199+
200+
Update-AzVM `
201+
-ResourceGroupName $vmRGName `
202+
-VM $myVM -Debug
203+
204+
Start-AzVM `
205+
-ResourceGroupName $vmRGName `
206+
-Name $vmName
207+
```
208+
209+
164210
## Clean up
165211

166212
You are being charged for your dedicated hosts even when no virtual machines are deployed. You should delete any hosts you are currently not using to save costs.
167213

168214
You can only delete a host when there are no any longer virtual machines using it. Delete the VMs using [Remove-AzVM](/powershell/module/az.compute/remove-azvm).
169215

170-
```powershell
216+
```azurepowershell-interactive
171217
Remove-AzVM -ResourceGroupName $rgName -Name myVM
172218
```
173219

174220
After deleting the VMs, you can delete the host using [Remove-AzHost](/powershell/module/az.compute/remove-azhost).
175221

176-
```powershell
222+
```azurepowershell-interactive
177223
Remove-AzHost -ResourceGroupName $rgName -Name myHost
178224
```
179225

180226
Once you have deleted all of your hosts, you may delete the host group using [Remove-AzHostGroup](/powershell/module/az.compute/remove-azhostgroup).
181227

182-
```powershell
228+
```azurepowershell-interactive
183229
Remove-AzHost -ResourceGroupName $rgName -Name myHost
184230
```
185231

0 commit comments

Comments
 (0)