xRemoteDesktopSessionHost icon indicating copy to clipboard operation
xRemoteDesktopSessionHost copied to clipboard

The resources should check is the RemoteDesktop module exists before loading it

Open TravisEz13 opened this issue 9 years ago • 7 comments

The resources should check is the RemoteDesktop module exists before loading it

TravisEz13 avatar Feb 24 '16 03:02 TravisEz13

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:

  1. Extend the Test-xRemoteDesktopSessionHostOsRequirement function
  2. Use a Try/Catch or alike functionality on import itself
  3. Use the Get-Command -Module RemoteDesktop -> When present, this should show results

I propose a combination of 1 and 2....?

peppekerstens avatar Aug 19 '18 06:08 peppekerstens

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?

johlju avatar Aug 19 '18 14:08 johlju

omg! you're so right! why didn't i think of that? lets first close current PR; in next one..ok? :)

peppekerstens avatar Sep 12 '18 17:09 peppekerstens

@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.

johlju avatar Sep 13 '18 09:09 johlju

Lets not re-invent: https://github.com/PowerShell/xDnsServer/blob/31cf3f61b8027fa7dda87d4d09216cff6f7f1f24/DSCResources/Helper.psm1#L35

peppekerstens avatar Sep 14 '18 08:09 peppekerstens

@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

johlju avatar Sep 14 '18 13:09 johlju

@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)?

johlju avatar Sep 14 '18 13:09 johlju