PowerShell 3 and more will attempt to automatically load modules if a command from that module is used and the module is under one of the paths in the %PSMODULEPATH% environment variable.
For example, if PowerShell is started and the PSDesiredStateConfiguration module is not imported, running the Get-DscResource command will cause the module to be imported. This is shown in the following example:
PS> Get-Module PSDesiredStateConfiguration
PS> Get-DscResource
PS> Get-Module PSDesiredStateConfiguration
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 1.1 PSDesiredStateConfiguration ...
In the previous example, the first time Get-Module is executed, the PSDesiredStateConfiguration module has not yet been loaded. After running Get-DscResource, a command from the PSDesiredStateConfiguration module, the module is loaded and the command is immediately executed. Once loaded, the module is visible when running Get-Module.
Modules in PowerShell may be explicitly imported using the Import-Module command. Modules may be imported using a name or with a full path, as shown by the following example:
Import-Module -Name PSWorkflow Import-Module -Name C:WindowsSystem32WindowsPowerShellv1.0ModulesPSWorkflowPSWorkflow.psd1
Once a module has been imported, the commands within the module may be listed using Get-Command as follows:
Get-Command -Module PSWorkflow
As the commands exported by a module can only be identified by importing the module, the previous command will trigger automatic import.
Modules installed in PowerShell 5 are placed in a folder named after the module version. This allows multiple versions of the same module to coexist, as shown in the following example:
Version 1.8.1 of PSScriptAnalyzer will be imported by default as it is the highest version number. It is possible to import a specific version of a module using the MinimumVersion and MaximumVersion parameters:
Import-Module PSScriptAnalyzer -MaxmimumVersion 1.7.0