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

MSFT_xRDSessionCollection: Collection related DSC fails when multiple collections are present #91

Closed RobBiddle closed 2 years ago

RobBiddle commented 3 years ago

Details of the scenario you tried and the problem that is occurring

xRDSessionCollection DSC fails on Windows Server 2019 if multiple RD Session Collections are present

Verbose logs showing the problem

[[xRDSessionCollection]Collection] Getting information about RDSH collection. Cannot process argument transformation on parameter 'CollectionName'. Cannot convert value to type System.String.

Suggested solution to the issue

Issue is caused by malfunctioning Get-RDSessionCollection cmdlet in Windows Server 2019. Microsoft will need to address the underlying issue. I'll be submitting a Pull Request with a workaround for the MSFT_xRDSessionCollection DSC Resource.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

The operating system the target node is running

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

Version and build of PowerShell the target node is running

PSVersion 5.1.17763.1490 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.17763.1490 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

Version of the DSC module that was used

RobBiddle commented 3 years ago

Some additional information on the bug.

Windows Server 2012R2 does not have the bug, Get-RDSessionCollection -CollectionName 'TestCollection1' will appropriately return the single collection 'TestCollection1', however the same command issued on Windows Server 2019 will return the full list of all collections rather than the single collection.

The bug is on the Windows Server 2019 client side. The command will give incorrect results when targeting a -ConnectionBroker running 2012, 2016 or 2019. Running the command from a Windows Server 2012R2 system targeting a Windows Server 2019 Connection Broker properly returns a single collection.

It's easy to reproduce.

danielboth commented 3 years ago

Hey Rob, thanks for reporting (and sorry for the late reply), looks like Microsoft implemented bug in W2019 / Win10 indeed. This is the W2019 code for Get-RDSessionCollection (for that part that gets the collection):

$wmiNamespace = "root\cimv2\rdms"

$cimSessionOption = New-CimSessionOption -PacketPrivacy
$cimSession = New-CimSession -ComputerName $ConnectionBroker -SessionOption $cimSessionOption

$options = New-Object Microsoft.Management.Infrastructure.Options.CimOperationOptions
$options.ShortenLifetimeOfResults = $true

$wmiClass = "Win32_RDSHCollection"
$rdSessionCollections = $cimSession.EnumerateInstances($wmiNamespace, $wmiClass, $options)

And this is what we used to have in W2016:

$wmiNamespace = "root\cimv2\rdms"
$wmiQuery = "SELECT * FROM Win32_RDSHCollection"
if($CollectionName)
{
    $wmiQuery = $wmiQuery + " WHERE Name='" + $CollectionName + "'"
}
$rdSessionCollections = Get-WmiObject -Namespace $wmiNamespace -Query $wmiQuery -ComputerName $ConnectionBroker -Authentication PacketPrivacy -ErrorAction Stop

So yes, looks like they switched from WMI to CIM and forgot to include the filtering for CollectionName in the new function. Did you report the bug to Microsoft?

RobBiddle commented 3 years ago

@danielboth I've attempted to report the bug through various channels with no response, but I don't know what the actual "official" method is for reporting Windows Server bugs to Microsoft.

I'll reach out to our Microsoft rep to see if I can get some traction on bug resolution.

arjenvri commented 1 year ago

Thank you, running into similar issues myself! Would it be possible to release this workaround possibly as a new version?