PowerShell 2.0: One Cmdlet at a Time 70 Import-Module
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Import-Module cmdlet.
What can I do with it?
PowerShell 2.0 introduces the concept of modules; essentially they are the evolution of snapins from PowerShell 1.0. Import-Module enables you to add one or more modules to your current session.
Examples:
Import the PSDiagnostics module and examine the newly available commands in the session from that module by using Get-Module.
Import-Module PSDiagnostics Get-Command -Module PSDiagnostics
You will see there are ten new functions available from that module.
Import only two functions, Start-Trace and Stop-Trace from the PSDiagnostics module and examine the newly available commands in the session from that module by using Get-Module.
Import-Module PSDiagnostics -Function Start-Trace,Stop-Trace Get-Command -Module PSDiagnostics
You will see that this time only those two functions are available.
How could I have done this in PowerShell 1.0?
You could have used the Add-PSSnapin cmdlet to import custom snapins typically produced by third-parties. For example to import the popular Quest AD cmdlets snapin you would use the below:
Add-PSSnapin Quest.ActiveRoles.ADManagement