How do I import a Powershell cmdlet globally from a function in another module?

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:

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:

Then in PowerShell I run:

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**

Source:

How do I import a Powershell cmdlet globally from a function in another module? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply