dsccommunity / xRemoteDesktopSessionHost

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

xRDCertificateConfiguration:The term ''Get-RDServer'' is not recognized #79

Closed lkys37en closed 2 years ago

lkys37en commented 4 years ago

ISSUE DESCRIPTION I'm using Ansible to run the xRDCertificateConfiguration resource and only when applying a certificate to the RDWebaccess role I get the following error message.

Failed to invoke DSC Set method: Failed to apply certificate from path ''C:\windows\temp\rds-cert.pfx'' to role ''RDWebAccess'' on connection broker ''hostnamel''. Error: ''The term ''Get-RDServer'' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.'''

Suggested solution to the issue

I figured this was an issue due to the box not being ready so I added a delay of 60 seconds and 10 retires and unfortunately the result is the same.

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

Output of successfully applying a certificate to other roles

TASK [ad_rds : Configure RDS Certificate] ****changed: [10.9.10.18] => (item=RDRedirector) => changed=true ansible_loop_var: item attempts: 1 item: RDRedirector module_version: 2.0.0 reboot_required: false changed: [10.9.10.18] => (item=RDPublishing) => changed=true ansible_loop_var: item attempts: 1 item: RDPublishing module_version: 2.0.0 reboot_required: false

The 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}

Version and build of PowerShell the target node is running

Name Value


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

Version of the DSC module that was used

Version 2.0.0

danielboth commented 4 years ago

Ok, looking at the error message you get this goes wrong at this stage:

https://github.com/dsccommunity/xRemoteDesktopSessionHost/blob/523c4356c411dfe10f9286011e5a147df90a2dc4/source/DSCResources/MSFT_xRDCertificateConfiguration/MSFT_xRDCertificateConfiguration.psm1#L92

Set-RDCertificate, in the beginning of the code, indeed calls Get-RDServer (which seems to be unavailable in your error).

The reason it's possible that command cannot be found is not entirely clear to me, it could be related to the fact that in the module where this command is defined (C:\windows\system32\WindowsPowerShell\v1.0\Modules\RemoteDesktop\Deployment.psm1) it's called Get-Server, not Get-RDServer. The RD prefix is only added as soon as the RemoteDesktop module is loaded.

Since this module loads the RemoteDesktop module explicitly, I would not expect any issues there though, but in this case it's clear there are issues.

Would you be so kind to help testing a change in the code? Maybe if we load the module in the global context, this prevents the issue. What you would need to do locally on your machine is change this line:

https://github.com/dsccommunity/xRemoteDesktopSessionHost/blob/523c4356c411dfe10f9286011e5a147df90a2dc4/source/DSCResources/MSFT_xRDCertificateConfiguration/MSFT_xRDCertificateConfiguration.psm1#L6

and make it: Import-Module -Name RemoteDesktop -Global

Then test it with your configuration. Thanks in advance!

lkys37en commented 4 years ago

That worked! Thank you so much and thank you for not saying because you're using Ansible I can't help you ( =

danielboth commented 4 years ago

Happy to hear that it worked, thank you for reporting back! To add to that, which tool you use, if it's Puppet, Chef, Ansible or plain DSC, that doesn't matter, in the end it's the DSC resource that needs to do the work.

jeremyciak commented 3 years ago

@danielboth are you looking for assistance in getting this fix implemented via a PR?

uw-dc commented 2 years ago

I hit this problem. PR raised.

@danielboth, @johlju please could we get this merged?