powershellpowershell-moduleimport-module

Is there ever a reason to explicitly Import-Module?


I was just reading the PowerShell Modules guide page and I noticed a line on the Import-Module section:

The following actions trigger automatic importing of a module, also known as "module auto-loading."

  • Using a cmdlet in a command. For example, typing Get-ExecutionPolicy imports the Microsoft.PowerShell.Security module that contains the Get-ExecutionPolicy cmdlet.

So given that, why should we ever care about using Import-Module? Isn't it always taken care for us automatically? In what case would I need to explicitly write out Import-Module?


Solution

  • You have to use Import-Module in the following cases :

    The list is not totally exhaustive but these are the main use cases for the Import-Module cmdlet.