1

#PSTip Cmdlet Discovery and Module auto-loading

In PowerShell 3.0, we no longer have to import modules manually to use cmdlets. When we run a cmdlet, Windows PowerShell imports the module that contains the command automatically. In addition, the Get-Command cmdlet now returns all cmdlets installed on the system, even if they are not in the current session.

We can enable, disable, and configure automatic importing of modules by using the $PSModuleAutoLoadingPreference preference variable. Valid values for this variable are: None, ModuleQualified, or All.

All Module auto-loading works for all commands. To import a module, get or use any command in the module.
None Module auto-loading is turned off. To import a module, use the Import-Module cmdlet.
ModuleQualified Modules are imported automatically only when a user uses the module-qualified name of a command. For example, if the user types “MyModule\MyCommand”, Windows PowerShell imports the MyModule module.

Alternatively, we can limit the command search scope and get only commands in the current session with the -ListImported switch parameter.

Get-Command <CommandName> -ListImported
Filed in: Columns, Tips and Tricks Tags: , , , , ,

One Pingback/Trackback

One Response to "#PSTip Cmdlet Discovery and Module auto-loading"

Leave a Reply

Submit Comment

© 9499 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: