Remote Desktop Services – High Availability Connection Broker and Powershell

I found RDS cmdlets a tad annoying since you must specify the single “ActiveManagementServer” name instead of the HA connection broker name.  If you omit the connection broker value you may see “A Remote Desktop Services deployment does not exist on server.contoso.com.  This operation can be performed after creating a deployment.  For information about creating a deployment, run “Get-Help New-RDVritualDesktopDeployment” or “Get-Help New-RDSessionDeployment”

A quick way to dynamically discover the ActiveManagementServer:

Import-Module RemoteDesktop

$CBfqdn = 'exampleHACB.contoso.com'
$CBservers = Resolve-DNsName $CBfqdn | % {(Resolve-DNSName $_.IPAddress)NameHost} | sort}
$CBservers | % {try{if(Test-Connection $_ -Count 1 -ea Stop){$AMS = Get-RDConnectionBrokerHighAvailability -ConnectionBroker $_).ActiveManagementServer}; break}catch{$null}}

$allApps = Get-RDRemoteApp -ConnectionBroker $AMS