Import-Module

Add modules to the current session. Beginning in PowerShell 3.0, modules are imported automatically when any cmdlet or function in the module is used in a command. This feature works on any module in a directory that is included in the value of the PSModulePath environment variable.

Syntax
      Import-Module [-Name] String[] [-Alias String[]] [-ArgumentList Object[]]
         [-AsCustomObject] [-Cmdlet String[]] [-DisableNameChecking] [-Force]
            [-Function String[]] [-Global] [-MinimumVersion] [-NoClobber] [-PassThru]
               [-Prefix String] [-RequiredVersion ] [-Scope String]
                  [-Variable String[]] [-PSSession PSSession] [CommonParameters]

      Import-Module [-Name] String[] [-Alias String[]] [-ArgumentList Object[]]
         [-AsCustomObject] [-CimNamespace String] [-CimResourceUri Uri]
            [-Cmdlet String[]] [-DisableNameChecking] [-Force] [-Function String[]] 
               [-Global] [-MinimumVersion ] [-NoClobber] [-PassThru]
                  [-Prefix String] [-RequiredVersion ] [-Scope String]
                     [-Variable String[]] -CimSession CimSession [CommonParameters]

      Import-Module [-Assembly] Assembly[] [-Alias String[]] [-ArgumentList Object[]]
         [-AsCustomObject] [-Cmdlet String[]] [-DisableNameChecking] [-Force]
            [-Function String[]] [-Global] [-NoClobber] [-PassThru] [-Prefix String]
               [-Scope String] [-Variable String[]] [CommonParameters]

      Import-Module [-ModuleInfo] PSModuleInfo[] [-Alias String[]] [-ArgumentList Object[]]
         [-AsCustomObject] [-Cmdlet String[]] [-DisableNameChecking] [-Force]
            [-Function String[]] [-Global] [-NoClobber] [-PassThru] 
               [-Prefix String] [-Scope String] [-Variable String[]] [CommonParameters]

Key
   -Alias String[]
       Import only the specified aliases from the module into the current session.
       Enter a comma-separated list of aliases. Wildcards permitted.
 
       Some modules automatically export selected aliases into your session when you
       import the module. This parameter lets you select from among the exported aliases.

   -ArgumentList Object[]
       Specifies arguments (parameter values) that are passed to a script module during
       the Import-Module command. Valid only when importing a script module.
       Refer to -ArgumentList by its alias, "args". For more see about_Aliases.

   -AsCustomObject
       Returns a custom object with members that represent the imported module members.
       Valid only for script modules.

       When you use -AsCustomObject, Import-Module will import the module members into the
       session and then return a PSCustomObject object instead of a PSModuleInfo object.
       Save the custom object in a variable and use dot notation to invoke the members.

   -Assembly Assembly[]
       Import the cmdlets and providers implemented in the specified assembly objects.
       Enter a variable that contains assembly objects or a command that creates assembly objects.
       You can also pipe an assembly object to Import-Module.

       When you use this parameter, only the cmdlets and providers implemented by the
       specified assemblies are imported. If the module contains other files, they are not imported,
       and you might be missing important members of the module.
       Use this parameter for debugging and testing the module, or when instructed by the module author.

   -CimNamespace String
       The namespace of an alternate CIM provider that exposes CIM modules.
       The default value is the namespace of the Module Discovery WMI provider.

       Use this parameter to import CIM modules from computers and devices that are not
       running a Windows OS. (PowerShell 3.0+)        

   -CimResourceUri Uri
       An alternate location for CIM modules. The default value is the resource URI of 
       the Module Discovery WMI provider on the remote computer.

       Use this parameter to import CIM modules from computers and devices that are not
       running a Windows OS. (PowerShell 3.0+)
        
   -Cmdlet String[]
       Import only the specified cmdlets from the module into the current session.
       Enter a list of cmdlets. Wildcards are permitted.

       Some modules automatically export selected cmdlets into your session when you import
       the module. This parameter lets you select from among the exported cmdlets.

   -DisableNameChecking
       Suppress the message that warns you when you import a cmdlet or function whose
       name includes an unapproved verb or a prohibited character.
        
       By default,  when a module that you import exports cmdlets or functions that have unapproved verbs in their 
       names, the PowerShell displays the following warning message:
       "Some imported command names include unapproved verbs which might make them less discoverable..."
        
       This message is only a warning. The complete module is still imported, including the non-conforming commands. 
       Although the message is displayed to module users, the naming problem should be fixed by the module author.
        
   -Force
       Re-import a module and its members, even if the module or its members have an access mode of read-only.
        
   -Function String[]
       Import only the specified functions from the module into the current session.
       Enter a list of functions. Wildcards are permitted.

       Some modules automatically export selected functions into your session when you import
       the module. This parameter lets you select from among the exported functions.
        
   -Global
       Import modules into the global session state so they are available to all commands in
       the session. By default, the commands in a module, including commands from nested modules,
       are imported into the caller's session state. To restrict the commands that a module exports,
       use an Export-ModuleMember command in the script module.
        
       The -Global parameter is equivalent to -Scope with a value of Global.
        
   -ModuleInfo PSModuleInfo[]
       Specify module objects to import. Enter a variable that contains the module objects, or
       a command that gets the module objects, such as a "Get-Module -ListAvailable" command.
       You can also pipe module objects to Import-Module.
        
   -Name String[]
       The names of the modules to import.
       Enter the name of the module or the name of a file in the module, such as a .psd1, .psm1,
       .dll, or ps1 file. File paths are optional. Wildcards are not permitted.
       You can also pipe module names and file names to Import-Module.
        
       If you omit a path, Import-Module looks for the module in the paths saved in the PSModulePath
       environment variable ($env:PSModulePath).
        
       Specify only the module name whenever possible. When you specify a file name, only the
       members that are implemented in that file are imported. If the module contains other files,
       they are not imported, and you may be missing important members of the module.
        
   -NoClobber
       Do not import commands that have the same names as existing commands in the current session.
       By default, Import-Module imports all exported module commands.
        
       Commands with the same names can hide or replace commands in the session.
       To avoid command name conflicts in a session, use the -Prefix or -NoClobber parameters.
       For more information see "Modules and Name Conflicts" in about_Modules and about_Command_Precedence.
       (PowerShell 3.0+)

   -PassThru
       Return objects that represent the modules that were imported.
       By default, this cmdlet does not generate any output.
        
   -Prefix String
       Add the specified prefix to the nouns in the names of imported module members.

       Use this parameter to avoid name conflicts that might occur when different members in
       the session have the same name. This parameter does not change the module, and it does
       not affect files that the module imports for its own use (known as "nested modules").
       It affects only the names of members in the current session.

       For example, if you specify the prefix "UTC" and then import a Get-Date cmdlet, the
       cmdlet is known in the session as Get-UTCDate, and it is not confused with the original Get-Date cmdlet.

       The value of this parameter takes precedence over the DefaultCommandPrefix property
       of the module, which specifies the default prefix.

   -Variable String[]
       Import only the specified variables from the module into the current session.
       Enter a list of variables. Wildcards are permitted.

       Some modules automatically export selected variables into your session when you import
       the module. This parameter lets you select from among the exported variables.

   -CimSession CimSession
       Specifies a CIM session on the remote computer.
       Enter a variable that contains the CIM session or a command that gets the CIM session,
       such as a Get-CimSession command.
        
       Import-Module uses the CIM session connection to import modules from the remote computer
       into the current session. When you use the commands from the imported module in the current
       session, the commands actually run on the remote computer.
        
       Use this parameter to import modules from computers and devices that are not running a
       Windows OS, and Windows computers that have PowerShell, but do not have PowerShell remoting enabled.
       (PowerShell 3.0+)
        
   -MinimumVersion Version
       Import only a version of the module that is greater than or equal to the specified value.
       If no version qualifies, Import-Module generates an error.

       By default, Import-Module imports the module without checking the version number.
       Use the -MinimumVersion parameter name or its alias, -Version.

       To specify an exact version, use the -RequiredVersion parameter. You can also use the -Module and 
       -Version parameters of the #Requires keyword to require a specific version of a module in a script.
       (PowerShell 3.0+)

   -PSSession PSSession
       Imports module from the specified PowerShell user-managed session ("PSSession") into the current 
       session. Enter a variable that contains a PSSession or a command that gets a PSSession, such as a 
       Get-CimSession command.

       When you import a module from a different session into the current session, you can use the cmdlets from 
       the module in the current session, just as you would use cmdlets from a local module.
       Commands that use the remote cmdlets actually run in the remote session, but the remoting details are
       managed in the background by PowerShell.

       This parameter uses the Implicit Remoting feature of PowerShell. It is equivalent to using the 
       Import-PSSession cmdlet to import particular modules from a session.

       Import-Module cannot import PowerShell Core modules from another session.
       The PowerShell Core modules have names that begin with Microsoft.PowerShell. (PowerShell 3.0+)
        
   -RequiredVersion Version
       Import only the specified version of the module.
       If the version is not installed, Import-Module generates an error.
        
       By default, Import-Module imports the module without checking the version number.
        
       To specify a minimum version, use the MinimumVersion parameter. You can also use the Module and Version 
       parameters of the #Requires keyword to require a specific version of a module in a script.
       (PowerShell 3.0+)
        
       Scripts that use the -RequiredVersion parameter to import modules that are included with existing
       releases of the Windows Operating System do not automatically run in future releases of the
       Windows OS. This is because PowerShell module version numbers in future releases of the Windows OS 
       are higher than module version numbers in existing releases of the Windows OS.
        
   -Scope String
       Import the module only into the specified scope.

        Valid values are:
        -- Global: Available to all commands in the session. Equivalent to the Global parameter.
        -- Local:  Available only in the current scope.
        By default, the module is imported into the current scope, which could be a script or module.
        (PowerShell 3.0+)

Standard Aliases for Import-Module: ipmo

Beginning in 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 $PSModuleAutoloading preference variable.

Import-Module imports a module only into the current session. To import the module into all sessions, add an Import-Module command to your PowerShell profile.

To manage remote Windows computers that have PowerShell and PowerShell remoting enabled, create a PSSession on the remote computer and then use Get-Module -PSSession to get the 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.

Examples

Import the members of the BitsTransfer module into the current session:

PS C:\> Import-Module -Name BitsTransfer

Import all available modules in the path specified by the PSModulePath environment variable:

PS C:\> Get-Module -ListAvailable | Import-Module

Import the members of the BitsTransfer and ServerManager modules into the current session:

PS C:\> $m = Get-Module -ListAvailable BitsTransfer, ServerManager
PS C:\> Import-Module -ModuleInfo $m

“Most imports are from outside of the country” ~ George W. Bush

Related PowerShell Cmdlets

Get-Module - Get the modules imported to the session.
Install-Module - Download and install modules from an online repository.
New-Module - Create a new dynamic module (only in memory) .
Remove-Module - Remove a module from the current session.
Export-ModuleMember - Export specific module members.


 
Copyright © 1999-2024 SS64.com
Some rights reserved