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:
function Import-Cmdlets
{
Import-Module "<dll path>" -Scope Global -Force
}
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:
function Import-Cmdlets
{
Import-Module "<dll path>" -Scope Global -Force
}
Then in PowerShell I run:
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?
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**
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With