You can import a PowerShell module using the Import-Module
cmdlet. This command loads the module's functions, variables, and other resources into your current PowerShell session, making them available for use.
Importing a Module
To import a module, use the following syntax:
Import-Module <Module Name>
Example:
To import the ActiveDirectory
module, you would use the following command:
Import-Module ActiveDirectory
Finding Available Modules
You can use the Get-Module
cmdlet to list all the modules available on your system. This command returns a list of modules, including their names, versions, and paths.
Example:
Get-Module -ListAvailable
Specifying Module Path
If the module you want to import is not in the default module path, you can specify its path using the -Path
parameter.
Example:
Import-Module -Path "C:\Modules\MyModule"
Importing Multiple Modules
You can import multiple modules using the Import-Module
cmdlet with multiple module names or paths.
Example:
Import-Module ActiveDirectory AzureAD
Unloading a Module
To unload a module, use the Remove-Module
cmdlet.
Example:
Remove-Module ActiveDirectory
Checking for Imported Modules
You can check which modules are currently loaded in your PowerShell session using the Get-Module
cmdlet without any parameters.
Example:
Get-Module
This will display a list of all the modules that are currently imported in your session.
Practical Insights
- Module dependencies: Some modules may have dependencies on other modules. If you try to import a module that has dependencies, PowerShell will automatically import the required dependencies.
- Module versions: Make sure that the module version you are importing is compatible with your PowerShell version.
- Module documentation: Most PowerShell modules come with documentation that explains how to use the module's functions and cmdlets. You can access this documentation by using the
Get-Help
cmdlet with the module name.