Skip to content

Commit 038eb6c

Browse files
author
Cynthia Nottingham
committed
tested syntax
1 parent 1920294 commit 038eb6c

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

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

Lines changed: 34 additions & 17 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 `
@@ -171,22 +171,39 @@ You can add an exiting VM to a dedicated host, but the VM must first be Stop\Dea
171171
- The VM can't be in an availability set.
172172
- 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.
173173

174+
Replace the values of the variables with your own information.
175+
174176
```azurepowershell-interactive
175-
$vmRGName = "myResourceGroup"
176-
$vmName = "myVM"
177+
$vmRGName = "movetohost"
178+
$vmName = "myVMtoHost"
177179
$dhRGName = "myDHResourceGroup"
178180
$dhGroupName = "myHostGroup"
179181
$dhName = "myHost"
180182
181-
$myDH = Get-AzHost -HostGroupName $dhGroupName -ResourceGroupName $dhRGName -Name $dhName
182-
183-
$myVM = Get-AzVM -ResourceGroupName $vmRGName -Name $vmName
184-
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+
185192
$myVM.Host = New-Object Microsoft.Azure.Management.Compute.Models.SubResource
186193
187-
$myVM.Host.Id = "/subscriptions/$subId/resourceGroups/$dhRGName/providers/Microsoft.Compute/hostGroups/$dhgName/hosts/$dhName"
188-
189-
Update-AzVM -ResourceGroupName $vmRGName -VM $myVM -Debug
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
190207
```
191208

192209

@@ -196,19 +213,19 @@ You are being charged for your dedicated hosts even when no virtual machines are
196213

197214
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).
198215

199-
```powershell
216+
```azurepowershell-interactive
200217
Remove-AzVM -ResourceGroupName $rgName -Name myVM
201218
```
202219

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

205-
```powershell
222+
```azurepowershell-interactive
206223
Remove-AzHost -ResourceGroupName $rgName -Name myHost
207224
```
208225

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

211-
```powershell
228+
```azurepowershell-interactive
212229
Remove-AzHost -ResourceGroupName $rgName -Name myHost
213230
```
214231

0 commit comments

Comments
 (0)