The Import-Module command
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...