Chapter 11
Activity
Try running Remove-Module
to get rid of the module we’ve just installed, and then running Get-Square
. What happens? Why does this happen?
The Get-Square
cmdlet is still available. This is because we saved the module in the module path correctly; this means that PowerShell will autoload the module when we call a function in the module. We can see it working in the following screenshot:
Figure A.13 – Autoloading with PowerShell
In the first line, I list the loaded modules. Then, I run Get-Square 7
, which autoloads MyFirstModule
. After that, I confirm that’s what happened by running Get-Module
again. We can see that Remove-Module
removes the Get-Square
cmdlet by running it with the -Verbose
switch in the last line.
Exercises
- Get-Module
- It imports a module into the global scope. Note that when we import a module from the command prompt, it is already imported into the global scope – we use...