Import PowerShell Module with Import-Module Commandlet

Powershell uses the modules in order to provide different commands, functions, variables, and aliases. Even most of the modules are provided as built-in which can be accessed directly some modules should be imported before using them. Over different PowerShell versions like PowerShell 1.0, PowerShell 2.0, and PowerShell 3.0, and later the importing module and usage are a bit changed. In this tutorial, we will learn how to import a module in PowerShell.

Import Module in PowerShell 1.0

In PowerShell version 1.0 there was no module. This means there is no specific command related to import modules. Instead the modules are implemented as Snap-ins in PowerShell version 1.0. The snap-ins should be registered in order to use the snap-ins contents.

Import Module in PowerShell 2.0

With the PowerShell 2.0 the modules are started to be used and the commendlet Import-Module is provided. The modules can be imported by using their names as parameter to the commendlet Import-Module. The modules are searched in the PSModulePath variable locations. The modules may have the extensions *.psd1 for module manifest, *.psm1 script module, *.dll for the binary module files. In the following example we import the module named MyCustomModule .

Import-Module MyCustomModule

If the module is not located under the PSModulePath we can import the module by specifying its path. This means we can import module from custom locations which are not searched by default. The option -Name is used to specify the path of the module and the name of the module. Alternatively, the option -Verbose can be used to print detailed information about the load operation.

Import-Module -Name "C:\MyModules\MyCustomModule" -Verbose

Import Module in PowerShell 3.0 and Later

The PowerShell version 3.0 provides some extra features for module importing. If one of the functions, variables are used in PowerShell the related module is automatically imported if the module is located under the PSModulePath. If the module is not located in the PSModulePath the module can be also loaded by using explicitly specifying the module with the option -Name like PowerShell version 2.0.

See also  How To Show/Unhide Hidden Files, Folders, or Drives In Windows?

List Available Modules

The PowerShell modules are stored in locations like C:\Program Files\WindowsPowerShell\Modules or C:\Windows\system32\WindowsPowerShell\v1.0\Modules . These modules are avaiable for usage. The available PowerShell modules can be listed with the Get-Module commandlet -ListAvailable option.

Get-Module -ListAvailable
List Available Modules

Import Available Modules

Also available modules can be imported explicitly by using the commandlet Import-Module. The available modules listed and redirected with the commandlet Get-Module.

Get-Module -ListAvailable | Import-Module

Leave a Comment