dsccommunity / xRemoteDesktopSessionHost

This module contains DSC resources for the management and configuration of Microsoft Remote Desktop Session Host (RDSH).
MIT License
35 stars 47 forks source link

xRDSessionCollection: Impossible to add a second Session Collection on Server 2019 #106

Closed uw-dc closed 1 year ago

uw-dc commented 1 year ago

Problem description

This relates to issue #91 which wasn't properly resolved by PR #92

In my use case, I am trying create an RDS deployment with two RD Session Collections, uxing `xRDSessionCollection.

The Test-TargetResource function in xRDSessionCollection relies on Get-TargetResource, within the same resource.

Get-TargetResource has been amended so that it filters the RD Session Collections on CollectionName matching the desired $CollectionName if there is more than one RD Session Collection returned from Get-RDSessionCollection, which had it's filtering removed (bug) when it was migrated from using WMI to CIM for Windows Server 2019.

https://github.com/dsccommunity/xRemoteDesktopSessionHost/blob/b97c82bc6eff7126d4a301f8f58a28ae21002c50/source/DSCResources/MSFT_xRDSessionCollection/MSFT_xRDSessionCollection.psm1#L30

I'm not sure why the change to xRDSessionCollection was implemented in this way, with a qualification around the filtering.

In the logs attached, there is no existing RD Session Collection called Test Collection, but because Test-TargetResource returns true, Set-TargetResource is never run.

Verbose logs

{"time": "2022-09-06T15:59:38.575+01:00", "type": "verbose", "message": "[RDS-BK1]: LCM:  [ Start  Resource ]  [[xRDSessionCollection]collection Test Collection]  "},
  {"time": "2022-09-06T15:59:38.591+01:00", "type": "verbose", "message": "[RDS-BK1]: LCM:  [ Start  Test     ]  [[xRDSessionCollection]collection Test Collection]  "},
  {"time": "2022-09-06T15:59:39.763+01:00", "type": "verbose", "message": "[RDS-BK1]:                            [[xRDSessionCollection]collection Test Collection] Checking for existence of RDSH collection."},
  {"time": "2022-09-06T15:59:39.778+01:00", "type": "verbose", "message": "[RDS-BK1]:                            [[xRDSessionCollection]collection Test Collection] Getting information about RDSH collection."},
  {"time": "2022-09-06T15:59:40.528+01:00", "type": "verbose", "message": "[RDS-BK1]: LCM:  [ End    Test     ]  [[xRDSessionCollection]collection Test Collection]  in 1.9380 seconds."},
  {"time": "2022-09-06T15:59:40.528+01:00", "type": "verbose", "message": "[RDS-BK1]: LCM:  [ Skip   Set      ]  [[xRDSessionCollection]collection Test Collection]  "},
  {"time": "2022-09-06T15:59:40.528+01:00", "type": "verbose", "message": "[RDS-BK1]: LCM:  [ End    Resource ]  [[xRDSessionCollection]collection Test Collection]  "},

DSC configuration

@{
                        CollectionName                 = 'Main Collection'
                        SessionHost                    = @('rdsh0.somedomain.sometld,rdsh1.somedomain.sometld')
                    }
                    @{
                        CollectionName                 = 'Test Collection'
                        SessionHost                    = @('rdsh2.somedomain.sometld')
                    }

~~~

    foreach ($collection in $Collections) {
        xRDSessionCollection "collection $($collection.CollectionName)" {
            CollectionName       = $collection.CollectionName
            SessionHost          = $collection.SessionHost[0]
            ConnectionBroker     = $ConnectionBroker
            PsDscRunAsCredential = $RDSDeploymentCredential
            DependsOn            = "[xRDSessionDeployment]RdsDeployment"
        }
    }

Suggested solution

Re-implment as:

$Collection = Get-RDSessionCollection `
    -CollectionName $CollectionName `
    -ConnectionBroker $ConnectionBroker `
    -ErrorAction SilentlyContinue | `
        Where-Object  CollectionName -eq $CollectionName

or

    $params = @{
        CollectionName   = $CollectionName
        ConnectionBroker = $ConnectionBroker
        ErrorAction      = 'SilentlyContinue'
    }

    $Collection = Get-RDSessionCollection @params  | `
        Where-Object  CollectionName -eq $CollectionName

... depending on preferred layout/coding standards

Operating system the target node is running

OsName               : Microsoft Windows Server 2019 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

PowerShell version and build the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.17763.2931
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.2931
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

xRemoteDesktopSessionHost version

Name                      Version Path
----                      ------- ----
xRemoteDesktopSessionHost 2.1.0   C:\Program Files\WindowsPowerShell\Modules\xRemoteDesktopSessionHost\2.1.0\xRemoteDesktopSessionHost.psd1