Automatically resolve unregistered machines in XenApp and XenDesktop 7

Problem:
After the nightly reboots of the XenApp servers it appears to happen that some of the machines are not able to register themselves at the delivery controller.

Solution:
The following PowerShell script needs to be run on the delivery controller. It will query the unregistered machines and restart the “BrokerAgent” service on them. Make sure the account has the correct privileges on the delivery controller and also on all remote servers to restart the services.
You can extend the script and exclude machines which are powered off in your hosting environment or just let the service restart time out on those machines.

Update: I created a small menu to display or resolve all unregistered VDAs.

function Show-Menu
 {
      param (
            [string]$Title = 'Resolve unregistered VDAs'
      )
      cls
      Write-Host "================ $Title ================"
      
      Write-Host "1: Press '1' for resolving issues."
      Write-Host "2: Press '2' for displaying issues."
      Write-Host "Q: Press 'Q' to quit."
 }

Asnp Citrix*

do
{
$unregisteredvdas = Get-BrokerDesktop -MaxRecordCount "9000" -Filter {RegistrationState -eq "Unregistered"}|Select-Object DNSName

Show-Menu
Write-Host "Please make a selection"
$key = [Console]::ReadKey()
$input= $key.KeyChar
switch($input)

{

'1'{
cls

if (!$unregisteredvdas){

Write-Output "No unregistered VDAs found"

}

else{

Write-Output "The follwing hosts are currently unregistered:"
$unregisteredvdas
Write-Output ""
Write-Output "Restarting BrokerAgent..."
ForEach ($entry in $unregisteredvdas.DNSName)
{
Write-Output "Restarting service on $entry ..."
Get-Service -ComputerName $entry -Name "BrokerAgent" | Restart-Service -Verbose
} 

}
}

'2'{
cls
if (!$unregisteredvdas){

Write-Output "No unregistered VDAs found"

}

else{

Write-Output "The follwing hosts are currently unregistered:"
$unregisteredvdas
}
}


'q'{
return
}
}
Write-Output ""
pause
}
until ($input -eq 'q')

References:
http://www.tomsitpro.com/articles/powershell-interactive-menu,2-961.html

Leave a Reply

Your email address will not be published. Required fields are marked *

*