PowerShell / WindowsCompatibility

Module that allows Windows PowerShell Modules to be used from PSCore6
Other
137 stars 33 forks source link

Import-Module Proxy Command #70

Open JustinGrote opened 5 years ago

JustinGrote commented 5 years ago

This is a great module, however it still requires scripts to be "rewritten" that have import-module natively in them.

I propose adding a command Register-WinImportModule, that will add a proxy command to import-module and use the following logic:

  1. If the module is available in PSCore PSModulePath, import it natively
  2. If not, check the Win5.1 PSModulePath. If the module is present and is supported in Core via CompatiblePSEditions manifest setting, import it natively.
  3. If it is present in PSModulePath but either not supported in core or CompatiblePSEditions is unspecified, Import-WinModule it.

I would end up using this in my PSCore scripts natively as well, so if I were to run, say, Import-Module ActiveDirectory, it will implicitly use the WindowsPowershell version until I get a PSCore Compatible version in place, and when I do, I don't have to rewrite my script to take advantage of it later. This would probably also require a small proxy to Get-Module to at least do a write-warning about the behavior and that Get-Module won't show all potential modules present. In the future, have the logic return all modules regardless of where they live.

I already have a version of this scaffolded, I'll be happy to write the PR if there is interest.