Windows PowerShell is a powerful automation platform that enables users to perform tasks quickly and efficiently. The Import-Module command is a powerful tool that allows users to import modules into their PowerShell environment. This command is used to load modules into the current session, and can be used to add new functionality to the environment. In this article, we will discuss the syntax, parameters, inputs, outputs, examples, and tips for using the Import-Module command.
Syntax
The syntax for the Import-Module command is as follows:
Import-Module [-Name] <String[]> [-ArgumentList <Object[]>] [-AsCustomObject] [-DisableNameChecking] [-Force] [-Global] [-Prefix <String>] [-PassThru] [-Scope <String>] [-Cmdlet <String[]>] [-Function <String[]>] [-Variable <String[]>] [-Alias <String[]>] [-FullyQualifiedName <String[]>] [-MinimumVersion <Version>] [-MaximumVersion <Version>] [-RequiredVersion <Version>] [-UseWindowsPowerShell] [-WarningAction <ActionPreference>] [-WarningVariable <String>] [-Confirm] [-WhatIf] [<CommonParameters>]
Parameters
The Import-Module command has several parameters that can be used to customize the command:
Parameter | Description |
---|---|
Name | Specifies the name of the module to be imported. |
ArgumentList | Specifies an array of arguments to be passed to the module. |
AsCustomObject | Specifies that the module should be imported as a custom object. |
DisableNameChecking | Specifies that the module should be imported without name checking. |
Force | Specifies that the module should be imported even if it is already imported. |
Global | Specifies that the module should be imported into the global scope. |
Prefix | Specifies a prefix to be used when importing the module. |
PassThru | Specifies that the imported module should be passed through the pipeline. |
Scope | Specifies the scope in which the module should be imported. |
Cmdlet | Specifies the cmdlets to be imported from the module. |
Function | Specifies the functions to be imported from the module. |
Variable | Specifies the variables to be imported from the module. |
Alias | Specifies the aliases to be imported from the module. |
FullyQualifiedName | Specifies the fully qualified names of the items to be imported from the module. |
MinimumVersion | Specifies the minimum version of the module to be imported. |
MaximumVersion | Specifies the maximum version of the module to be imported. |
RequiredVersion | Specifies the required version of the module to be imported. |
UseWindowsPowerShell | Specifies that the module should be imported using Windows PowerShell. |
WarningAction | Specifies the action to be taken when a warning is encountered. |
WarningVariable | Specifies the variable in which to store the warning. |
Confirm | Prompts the user for confirmation before executing the command. |
WhatIf | Displays the changes that would be made by the command without actually executing the command. |
Inputs
The Import-Module command takes the following inputs:
- Name – The name of the module to be imported.
- ArgumentList – An array of arguments to be passed to the module.
- Prefix – A prefix to be used when importing the module.
- Scope – The scope in which the module should be imported.
- Cmdlet – The cmdlets to be imported from the module.
- Function – The functions to be imported from the module.
- Variable – The variables to be imported from the module.
- Alias – The aliases to be imported from the module.
- FullyQualifiedName – The fully qualified names of the items to be imported from the module.
- MinimumVersion – The minimum version of the module to be imported.
- MaximumVersion – The maximum version of the module to be imported.
- RequiredVersion – The required version of the module to be imported.
- UseWindowsPowerShell – Whether the module should be imported using Windows PowerShell.
- WarningAction – The action to be taken when a warning is encountered.
- WarningVariable – The variable in which to store the warning.
Outputs
The Import-Module command does not produce any output.
Examples
The following examples demonstrate how to use the Import-Module command:
Example 1: Import a module
The following command imports the MyModule module into the current session:
Import-Module -Name MyModule
Example 2: Import a module with a prefix
The following command imports the MyModule module into the current session with the prefix MyPrefix:
Import-Module -Name MyModule -Prefix MyPrefix
Example 3: Import a module with a minimum version
The following command imports the MyModule module into the current session with a minimum version of 2.0:
Import-Module -Name MyModule -MinimumVersion 2.0
Tips
When using the Import-Module command, keep the following tips in mind:
- The Name parameter is required.
- The Prefix parameter is optional, but can be useful for avoiding name conflicts.