PowerTip: Find and Import Modules


Summary: Learn how to find and import Windows PowerShell modules.

Hey, Scripting Guy! Question I want to get a list of all the modules that are installed with Windows PowerShell on my machine. How can you do this?

Hey, Scripting Guy! Answer Inside a Windows PowerShell console, type the following command:

Get-Module -ListAvailable

Hey, Scripting Guy! Question I want to load all of the modules that are installed with Windows PowerShell on my machine. How can you do this?

Hey, Scripting Guy! Answer Inside a Windows PowerShell console, type the following command:

Get-Module –ListAvailable | import-module

Comments (5)

  1. Walid Toumi says:

    Hi Ed,

    you can also import dynamic modules:

    PS II>  New-Module -Name DynamicModule -Script {

     function hello { b $args[0] }

     function b($name) { write "hello $name" }

    } -function hello | Import-Module -PassThru -Verbose

    PS II> hello $env:USERNAME

  2. Ed Wilson says:

    @Walid Toumi that is a great tip thank you for sharing it. Let me ask you, how would you use a dynamic module? When does it make sense to you to do this?

  3. Walid Toumi says:

    @Ed

    1- i use "New-Module" with "AsCustomObject" parameter to convert my dynamic modules into objects members and make their use simple

    PS II>

    $objMod=New-Module -Name DynamicModule -Script {

    function hello { b $args[0] }

    function b($name) { write "hello $name" }

    } -function hello | Import-Module -PassThru -Verbose -AsCustomObject

    PS II> $objMod.hello("$env:username")

    2- i use "New-Module" because is in memory not in disk and much easier to quickly group functions in memory and make them as a unit

    (sorry for my english)

  4. neil1775 says:

    CORRECTED:
    To load any module upon opening PowerShell, do the following:
    1. Open PowerShell
    2. Type: $profile
    3. Create the path and file if required –OR– for all PowerShell/ISE/USERS: create the file C:WindowsSystem32WindowsPowerShellv1.0profile.ps1
    4. Open the .ps1 in PowerShellISE
    5. Modify to include modules you require, i.e.: Import-Module ActiveDirectory
    6. Save
    7. Test (close all PowerShells, open new one)
    8. Cake?