I am trying to get all not used SessionHosts in a RDS Deployment.
At the end of the code I get two lists with all SessionHosts and all used SessionHosts and these two lists I want to compare to get all unused hosts.
For the comparison, I tried https://stackoverflow.com/a/6368667/6708104 .
# ALL SessionHosts
$RDSessionHost = (Get-RDserver -Role "RDS-RD-SERVER" -ConnectionBroker $ConnectionBrooker).Server
Write-Host "Alle SessionHosts:" -ForegroundColor Green
# All SessionCollections
$RDSessionCollections = (Get-RDSessionCollection -ConnectionBroker $ConnectionBrooker).Collectionname
# ALL used SessionHosts
foreach($p in $RDSessionCollections){
$used = (Get-RDSessionHost -CollectionName $p -ConnectionBroker $ConnectionBrooker).SessionHost
}
#ALL unused SessionHosts
$unused = ($RDSessionHost | Where {$used -NotContains $_})
Result
ALL SessionHosts:
SessionHost1
SessionHost2
SessionHost12
SessionHost11
SessionHost10
SessionHost9
SessionHost6
SessionHost8
SessionHost5
SessionHost3
SessionHost4
SessionHost7
ALL USED SessionHosts:
SessionHost1
SessionHost2
SessionHost11
SessionHost10
SessionHost9
SessionHost6
SessionHost7
SessionHost5
SessionHost4
SessionHost3
ALL UNUSED SessionHosts:
SessionHost1
SessionHost2
SessionHost12
SessionHost11
SessionHost10
SessionHost9
SessionHost6
SessionHost8
SessionHost5
SessionHost3
SessionHost4
SessionHost7
But there are only two unused: SessionHost8 and SessionHost12