concept Import - Module in category powershell

This is an excerpt from Manning's book Windows PowerShell in Action, Third Edition.
In this section, we’ll cover what happens when modules import other modules. Because Import-Module is a regular cmdlet, it can be called from anywhere. When it’s called from inside another module, the result is a nested module. A nested module is only directly visible to the calling module. This is much easier to show than to explain. Let’s look at a module called usesCount.psm1.
When one module loads another, by default it becomes a nested module. This is usually what you want, but perhaps you want to write a module that manipulates modules. In this scenario, you need to be able to import the module into a context other than your own. Although there isn’t a way to import directly into an arbitrary context, the -Global flag on Import-Module allows you to import into the global context. Let’s work on a variation of the usesCount module to see how this works. The modified script module is shown next.
Listing 8.5. usesCount2.psm1
Import-Module -Global .\counter2.psm1 function CountUp ($x) { while ($x-- -gt 0) { Get-Count } }The significant difference in this version is the use of the -Global parameter on Import-Module. First, import the module: