#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.

AllModule auto-loading works for all commands. To import a module, get or use any command in the module.
NoneModule auto-loading is turned off. To import a module, use the Import-Module cmdlet.
ModuleQualifiedModules 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
Share on: