If you are familiar with ARM and BICEP you can also incorporate this option into code. During the VM deployment you'll want to specify an additional section within the properties for the host and id.
https://github.com/JCoreMS/HostPoolDeployment/blob/1ae358e99d1f13d55da0c09173dedd08677e4fcb/modules/virtualmachines.bicep#L121
If you'd like to see what an AVD Host Pool deployment via code looks like take a look at this one:
JCoreMS/HostPoolDeployment (github.com)
I worked on this today and had the need to just move some VMs to a dedicated host. However, I didn't want to impact the existing VMs running so resorted to an option with Tags to determine if the script should execute against them. Given we added some new VMs to the Host Pool that had existing VMs already moved to the dedicated host this is what I came up with. Essentially the deployment will be done with the VMs having a Tag key pair added of "DedicatedHost" and "New". The script will search for that key in the Tag and if it is "New" will then process the VM to move and update the Tag Value of "New" to that of the specified Dedicated Host Name. Thus, leaving you with a Tag of "DedicatedHost" and in this case "dh-eus2-avd-001".
Free for re-use of course and I plan on updating my BICEP to see if I can deploy directly to a dedicated host as well. Most importantly we hope to see this as an option in the native AVD portal soon. But for now....
#####################################
# Move VMs to New Hosts based on Tag
#####################################
$HostGroupName = "hg-eus2-avd"
$ResourceGroupDH = "rg-eastus2-DedicatedHostResources" # DH = Dedicated Host
$DedicatedHostName = "dh-eus2-avd-001"
$HostPoolName = "hp-eus2-OfficeUsers"
$ResourceGroupAVD = "rg-eastus2-AVD-Resources"
$ResourceGroupVM = "rg-eastus2-AVDVMs-OfficeUsers"
$tagKey = "DedicatedHost"
$tagValue = "New"
$myDH = Get-AzHost -HostGroupName $HostGroupName -ResourceGroupName $ResourceGroupDH -Name $DedicatedHostName
$VMs = Get-AZWVDSessionHost -ResourceGroupName $ResourceGroupAVD -HostPoolName $HostPoolName
Foreach ($VM in $VMs) {
$DNSname = $VM.name.split("/")[1]
$VMname = $DNSname.split(".")[0]
If((Get-AzVM -ResourceGroupName $ResourceGroupVM -Name $VMname).Tags[$tagKey] -eq $tagValue) {
$myVM = Get-AzVM -ResourceGroupName $ResourceGroupVM -Name $VMname
Write-Host "Moving VM $VMname to Dedicated Host $DedicatedHostName..." -ForegroundColor Green
$myVM.Host = New-Object Microsoft.Azure.Management.Compute.Models.SubResource
$myVM.Host.Id = $myDH.Id
Stop-AzVM -ResourceGroupName $ResourceGroupVM -Name $VMname -Force
Update-AzVM -ResourceGroupName $ResourceGroupVM -VM $myVM
Start-AzVM -ResourceGroupName $ResourceGroupVM -Name $VMName
# Update Tag with Dedicated Host Name
$myVM.Tags[$tagKey] = $DedicatedHostName
Update-AzTag -ResourceId $myVM.Id -Tag $myVM.Tags -Operation Merge
}
else {
Write-Host "VM $VMname is not tagged for move to Dedicated Host" -ForegroundColor Yellow
}
}