Question:
I’m hitting a problem importing cmdlet globally from a function in another module.
Here is the case. Say I’m trying to call Test-Method
in an dll.
When I run Import-Module <dll path>
, things work normally and I can call the Test-Method
with no problem.
Then I put the command into a function to simplify usage. Now I have something like:
1 2 3 4 5 |
function Import-Cmdlets { Import-Module " } |
Now in Powershell I call Import-Cmdlets
, and then I can call Test-Method
with no problem.
However, when I put the function into a psm1 file, and import module on the psm1 file, I cannot find Test-Method
anymore.
Now I have a mymodule.psm1
file with following content:
1 2 3 4 5 |
function Import-Cmdlets { Import-Module " } |
Then in PowerShell I run:
1 2 3 |
Import-Module mymodule.psm1 -Force Import-Cmdlets |
Now I cannot find Test-Method
any more. The dll shows up when I run Get-Module
and I can see Test-Method
from ExportedCommands. But I cannot access it.
This only happens for dll imports. I’ve tried to use a psm1 file to replace the dll path, and didn’t meet this issue.
What is a good work around or solution for this problem?
Answer:
I had the same problem and adding the parameter -Scope Global fixed it
Change your line to Import-Module <path to your module> **-Scope Global**