Fixing AVD Session Hosts That Never Joined the Domain

While working through an Azure Virtual Desktop deployment, we found something that should never happen: session hosts in the host pool that were never actually joined to Active Directory. They were registered with the host pool and looked fine at a glance, but users couldn’t get a working session on them. This post walks through how to confirm which hosts are affected and the two ways to fix them: joining them in place with Add-Computer, or adding the domain join extension (JsonADDomainExtension) from Azure.

How it shows up

A session host that isn’t domain-joined can still have the AVD agent installed and registered, so it shows up in the host pool like everything else. The clues are usually:

  • The session host name in the portal is just the VM name, with no domain suffix on the end.
  • The host’s health checks show a failure on the domain-joined or domain trust check.
  • Domain users can’t sign in, or they land on a host with no GPOs, no drive mappings and no FSLogix profile.

Note that this is easy to miss in a hybrid setup. If the VM was Entra joined, or the domain join step in the deployment failed quietly, the host can look healthy enough until a real user tries it.

Step 1: Check every host in the pool

Rather than RDPing into each VM, we can ask Azure to run a quick check on all of them. This uses the Az.DesktopVirtualization and Az.Compute modules. It pulls every session host in the pool, then uses Run Command to ask each VM whether it’s part of a domain.

# Requires Az.Accounts, Az.Compute and Az.DesktopVirtualization
$ResourceGroup = '[Host Pool Resource Group]'
$HostPool      = '[Host Pool Name]'

Connect-AzAccount

$check = '$cs = Get-CimInstance Win32_ComputerSystem; "{0}|{1}" -f $cs.PartOfDomain, $cs.Domain'

$results = foreach ($sh in Get-AzWvdSessionHost -ResourceGroupName $ResourceGroup -HostPoolName $HostPool) {
    # ResourceId points at the VM behind the session host
    $vmRg   = ($sh.ResourceId -split '/')[4]
    $vmName = ($sh.ResourceId -split '/')[-1]

    $out = Invoke-AzVMRunCommand -ResourceGroupName $vmRg -VMName $vmName `
        -CommandId 'RunPowerShellScript' -ScriptString $check
    $joined, $domain = ($out.Value[0].Message.Trim()) -split '\|'

    [pscustomobject]@{
        VM           = $vmName
        Status       = $sh.Status
        PartOfDomain = $joined
        Domain       = $domain
    }
}

$results | Sort-Object PartOfDomain, VM | Format-Table -AutoSize

Anything showing False with a domain of WORKGROUP needs fixing. Run Command goes one VM at a time and each call takes a little while, so give it a few minutes on a bigger pool. If your version of Az.Compute doesn’t support -ScriptString, save the check to a .ps1 file and use -ScriptPath instead.

If you’re already on the box, dsregcmd /status tells you the same thing. Look at DomainJoined and AzureAdJoined near the top of the output.

Step 2: Drain the affected hosts

Both fixes need a reboot, so stop new sessions from landing on the broken hosts first:

Update-AzWvdSessionHost -ResourceGroupName $ResourceGroup -HostPoolName $HostPool `
    -Name '[Session Host Name]' -AllowNewSession:$false

Use the session host name exactly as Get-AzWvdSessionHost shows it, minus the host pool prefix in front of the slash.

Step 3, option A: Join in place with Add-Computer

For a handful of hosts, the quickest path is joining them by hand. Connect to the VM with the local admin account (Bastion works well here), open an elevated PowerShell window and run:

Add-Computer -DomainName '[domain.com]' `
    -OUPath 'OU=SessionHosts,OU=AVD,DC=domain,DC=com' `
    -Credential (Get-Credential DOMAIN\account) `
    -Restart

A few things to watch for:

  • The VM has to be able to find a domain controller. Check that the VNet’s DNS servers point at your DCs (or a resolver that forwards to them), not Azure’s default DNS.
  • Put the host in the OU where your AVD GPOs are linked. Joining into the default Computers container gets you a domain-joined host with none of the settings you actually need.
  • It’s tempting to push Add-Computer through Run Command to do them all at once, but Run Command can’t prompt for credentials. That means putting the join account’s password in a script, which isn’t worth it. If you need to do a lot of hosts, use option B.

Step 3, option B: Add the domain join extension

The JsonADDomainExtension is the same extension the AVD deployment uses to join hosts in the first place. Adding it to an existing VM does the join from the Azure side, and the password goes in the extension’s protected settings so it’s encrypted instead of sitting in plain text.

$cred = Get-Credential -Message 'Domain join account (user@domain.com)'

$settings = @{
    Name    = '[domain.com]'
    OUPath  = 'OU=SessionHosts,OU=AVD,DC=domain,DC=com'
    User    = $cred.UserName
    Restart = 'true'
    Options = 3   # 1 = join domain, 2 = create computer account; 3 = both
}
$protected = @{ Password = $cred.GetNetworkCredential().Password }

Set-AzVMExtension -ResourceGroupName '[VM Resource Group]' -VMName '[VM Name]' `
    -Location '[Region]' -Name 'joindomain' `
    -Publisher 'Microsoft.Compute' -ExtensionType 'JsonADDomainExtension' `
    -TypeHandlerVersion '1.3' `
    -Settings $settings -ProtectedSettings $protected

Wrap that in a loop over the False hosts from Step 1 and you can fix the whole pool in one pass. If the extension fails, the error in the portal under the VM’s Extensions blade is usually specific enough to point at the problem: bad credentials, DNS that can’t find the domain, or an OU path typo.

Note that if a host was deployed as Entra joined and you want it AD joined instead, it’s usually cleaner to remove it from the host pool and redeploy it with the right join type than to try and convert it in place.

Step 4: Verify and put the hosts back in rotation

  1. Re-run the Step 1 script and confirm every host shows True with your domain.
  2. Check the session host in the portal. The name should now include the domain suffix, and the health checks should be clean once the agent reports in again.
  3. Sign in with a test domain user and make sure GPOs apply (gpresult /r) and the profile mounts.
  4. Turn new sessions back on with Update-AzWvdSessionHost ... -AllowNewSession:$true.

A note on multi-forest environments

If your users live in a different forest than the one the session hosts join, a successful domain join is only half the job. The hosts’ domain has to trust the users’ domain, the DNS used by the VNet has to resolve both forests, and the user accounts have to be synced to Entra ID for AVD sign-in to work. Test with a user from each forest before you call it done.

Wrapping up

A session host that skipped the domain join can sit in a pool for a while before anyone notices. A quick Run Command sweep finds them, Add-Computer fixes one or two by hand, and the JsonADDomainExtension handles the rest without passwords in scripts. It’s also worth adding that Step 1 check to your post-deployment validation so the next batch of hosts gets caught before users do.

Leave a Reply