Get-xRDS_CollectionsList.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function Get-xRDS_CollectionsList ([Parameter(Mandatory=$true)][string]$ConnectionBroker,[PSCredential]$Credential) {

    $Collection = @{}
    $OutCollection = @{}
    
    Try {

        $ActiveManagementServer =  (Invoke-WmiMethod -ComputerName $ConnectionBroker -Class "Win32_RDMSEnvironment" -Namespace "root\CIMV2\rdms" -Name "GetActiveServer").ServerName

        Get-WmiObject -Credential $Credential -ComputerName $ActiveManagementServer -Query "SELECT Alias, Name FROM Win32_RDSHCollection" -Namespace "root\CIMv2\rdms" | %{$Collection.Add($_.alias,$_.name)}
        Get-WmiObject -Credential $Credential -ComputerName $ActiveManagementServer -Query "SELECT Name, CollectionAlias FROM Win32_RDSHServer" -Namespace "root\CIMv2\rdms" | %{$OutCollection.Add(($_.Name),$Collection[$_.CollectionAlias])}
    }
    
    Catch {Write-host $_.Exception.message -ForegroundColor Red} 
    
    return $OutCollection
}