PowerTip: Find and Import Modules

PowerTip: Find and Import Modules

  • Comments 5
  • Likes

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

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • 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

  • @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?

  • @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)

  • basic but essential

  • 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:\Windows\System32\WindowsPowerShell\v1.0\profile.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?