Contact Info

Crumbtrail

ActiveXperts.com » Administration » Powershell » Powershell 4.0 » Import-Module

Import-Module - Powershell 4.0 CmdLet

ActiveXperts Network Monitor ships with integrated Powershell scripts to monitor complex network. The scripts run out of the box
Download the ActiveXperts Network Monitor FREE version now »

Import-Module

Short description
Adds modules to the current session.

Syntax


Description
The Import-Module cmdlet adds one or more modules to the current session. The modules that you import must be 
installed on the local computer or a remote computer.


Beginning in Windows PowerShell 3.0, installed modules are automatically imported to the session when you use any 
commands or providers in the module. However, you can still use the Import-Module command to import a module and you 
can enable and disable automatic module importing by using the $PSModuleAutoloadingPreference preference variable. For 
more information about modules, see about_Modules (http://go.microsoft.com/fwlink/?LinkID=144311). For more 
information about the $PSModuleAutoloadingPreference variable, see about_Preference_Variables 
(http://go.microsoft.com/fwlink/?LinkID=113248).


A module is a package that contains members (such as cmdlets, providers, scripts, functions, variables, and other 
tools and files) that can be used in Windows PowerShell. After a module is imported, you can use the module members in 
your session.


To import a module, use the Name, Assembly,  ModuleInfo, MinimumVersion and RequiredVersion parameters to identify the 
module to import. By default, Import-Module imports all members that the module exports, but you can use the Alias, 
Function, Cmdlet, and Variable parameters to restrict the members that are imported. You can also use the NoClobber 
parameter to prevent Import-Module from importing members that have the same names as members in the current session.


Import-Module imports a module only into the current session. To import the module into all sessions, add an 
Import-Module command to your Windows PowerShell profile. For more information about profiles, see about_Profiles 
(http://go.microsoft.com/fwlink/?LinkID=113729).


Also, beginning in Windows PowerShell 3.0, you can use Import-Module to import Common Information Model (CIM) modules, 
in which the cmdlets are defined in Cmdlet Definition XML (CDXML) files. This feature allows you to use cmdlets that 
are implemented in non-managed code assemblies, such as those written in C++.


With these new features, Import-Module cmdlet becomes a primary tool for managing heterogeneous enterprises that 
include Windows computers and computers that are running other operating systems.


To manage remote Windows computers that have Windows PowerShell and Windows PowerShell remoting enabled, create a 
PSSession on the remote computer and then use the PSSession parameter of Get-Module to get the Windows PowerShell 
modules in the PSSession. When you import the modules, and then use the imported commands in the current session, the 
commands run implicitly in the PSSession on the remote computer. You can use this strategy to manage the remote 
computer.


You can use a similar strategy to manage computers that do not have Windows PowerShell remoting enabled, including 
computers that are not running a Windows operating system, and Windows computers that have Windows PowerShell, but do 
not have Windows PowerShell remoting enabled.


Begin by creating a "CIM session" on the remote computer; a connection to Windows Management Instrumentation (WMI) on 
the remote computer. Then use the CIMSession parameter of Import-Module to import CIM modules from the remote 
computer. When you import a CIM module and then run the imported commands, the commands run implicitly on the remote 
computer. You can use this WMI and CIM strategy to manage the remote computer.