PowerTip: Find and Import Modules

PowerTip: Find and Import Modules

Rate This
  • Comments 4

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

Leave a Comment
  • Please add 1 and 3 and type the answer here:
  • Post
  • 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

Page 1 of 1 (4 items)