Scripting. Powershell, VMware, Windows, Active Directory & Exchange. All that kind of stuff…..
RSS icon Email icon Home icon
  • PowerShell 2.0: One Cmdlet at a Time #70 Import-Module

    Posted on March 3rd, 2010 Jonathan Medd No comments

    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-Module1

    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.

    Import-Module2

    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

    1000 things 1% better!

    Leave a reply