The resources should check is the RemoteDesktop module exists before loading it
The resources should check is the RemoteDesktop module exists before loading it
struggling a bit with what is expected as the RemoteDesktop module implicitly exists on a Windows server when function Test-xRemoteDesktopSessionHostOsRequirement from xRemoteDesktopSessionHostCommon.ps1 passes.
Only situation when this happens is when it is not called from a server OS. Should the Test-xRemoteDesktopSessionHostOsRequirement function be extended to test that?
Also, you cannot test on:
- 'Get-WindowsFeature RSAT-RDS-Tools' as it is not needed to to import th module
- 'Get-Module RemoteDesktop' as this yields no result on a server OS
- 'Get-Package RemoteDesktop' as this yields to an errort on a server OS
- Any of the "Find-' commands of the above, as this will show results from PSGallery which we do not want.
What remains:
- Extend the Test-xRemoteDesktopSessionHostOsRequirement function
- Use a Try/Catch or alike functionality on import itself
- Use the Get-Command -Module RemoteDesktop -> When present, this should show results
I propose a combination of 1 and 2....?
My thought is that Get-Module -Name RemoteDesktop -ListAvailable, if the module is in a $PSModulePath then this will return the module. If it does not exist, it will return $null (nothing).
Would that work?
omg! you're so right! why didn't i think of that? lets first close current PR; in next one..ok? :)
@peppekerstens It is always easier to have someone to bounce ideas with. You would have figured it out 🙂 No problem doing this in another PR.
Lets not re-invent: https://github.com/PowerShell/xDnsServer/blob/31cf3f61b8027fa7dda87d4d09216cff6f7f1f24/DSCResources/Helper.psm1#L35
@peppekerstens that's perfect to copy that helper function over here. :) Let's put it a module like it's done here (some folder structure and change the name accordingly). https://github.com/PowerShell/CertificateDsc/tree/dev/Modules/CertificateDsc.ResourceHelper
@PlagueHO what's the difference between CertificateDsc.Common and CertificateDsc.ResourceHelper? 🤔 See https://github.com/PowerShell/CertificateDsc/tree/dev/Modules
If we should create a helper module here, what should we name it (to be consequent with template/other modules)?