PowerTip: Display All PowerShell Modules and Cmdlets


Summary: Learn how to display all Windows PowerShell modules and cmdlet names.

Hey, Scripting Guy! Question How can I get output that shows Windows PowerShell module names and the cmdlets or functions that are contained inside the modules?

Hey, Scripting Guy! Answer Use the Get-Module cmdlet, and then for each module, display the name and use Get-Command (gcm is an alias) to retrieve the cmdlets and functions (this is a single-line command broken at the pipe character for readability):

Get-Module -ListAvailable |

foreach {"`r`nmodule name: $_"; "`r`n";gcm -Module $_.name -CommandType cmdlet, function | select name}

Comments (19)

  1. jrv says:

    The first job of any technician or and tech-wannabe is to learn how to find and read the documentation.  Once you have mastered this very complex technical challenge all other issues technical are at you command.

    As it was in the Dark ages.  There was no printing.  There was no information.  Only the priests had knowledge.  They would share it but you could not get any of the few “books” that were available.  

    Along comes a guy named Guttenberg and all of that changed.  The elite priesthood was deposed and even peasants could learn to read and partake of the secret knowledge.

    Much later, in the days of slavery, reading was outlawed for slaves.  This was done to prevent the slaves from becoming the masters.  Of course we know now how much of a failure this was.

    Dictators, like Hitler, rewrite books to tell the story as they want to see it.  They make all come to them for knowledge.

    The true liberator is the teacher who teaches others how to read.  The Saints and Liberators of the modern world, Jesus, Muhammad, Buddha and others all gave their followers autonomy from the elite priesthood of their time.  They all taught their followers how to find the answers for themselves.  Screw the Priests, the Gurus and the pundits.

  2. jrv says:

    Placing semicolons between every statement does not make a one-liner.  It just makes people irritated because it cannot be read.

  3. jrv says:

    Useful…

    Get all commands in all modules loaded and not loaded grouped by module:

    get-module -all | %{ get-command -module $_.Name } |ft -group modulename

  4. jrv says:

    @K

    Much better.  

    Now if someone would fix the style sheet for this web site it would even be readable. Readable code is preferred and helps to avoid implementation errors.

  5. jrv says:

    if($out -eq $NULL)

    IS REDUNDANT AND KLUNKY.

    if(!$out){ … }

    Much more PowerShell-like.  It also reads better.

  6. jrv says:

    @sevengs

    The blog posts are excellent but they suppose  certain basic understanding.  Here is a link to help you acquire that understanding:   technet.microsoft.com/…/bb291022.aspx

  7. Anonymous says:

    Thanks Guys, that cleared it up heaps!

    Now instead of just copying and pasting bits I am starting to work out how I can use it for other things.

    I wish that was how all the blog posts were done, I find the odd one here or there that are like this but when I am just starting it is really hard..

    I have only just tried powershell for the first time 2 weeks ago.. but wish I started a long time ago as I was using VBS before but it never made sense to me, this on the other hand is much easier for me to grasp how it works. I don't know all the commands, but am learning how to find them and that was something I could never do in VBS..

  8. jrv says:

    @Me – why we say more explicit more better.

    Get-Module -ListAvailable |

       ForEach-Object{

            Write-host ('Module Name:{0}' -f $_) -fore green -back blue

             gcm -Module $_.name -CommandType cmdlet, function |

                   ForEach-Object{

                        Write-Host ("`t{0}" -f $_.Name) -fore white -back blue

                   }

       }

  9. Anonymous says:

    Hmm, the site changed my name, but I made the first post as @Me

    Can someone explain this bit?

    %{"`r`nmodule name: $_"; "`r`n"

  10. Anonymous says:

    Thanks!!

    I looked in the help everywhere yesterday and just could not find it, also if you try to search just those symbols on the internet.. well you can guess what happens..

    These help files are awesome when you know where to find them 😀

    Thanks again for taking the time to explain all this to me, it was no small thing.

  11. Krunch {The Commenter formerly known as K} says:

    Version_2:

    gmo -ListAvailable | %{"`r`nmodule name: $_"; "`r`n";$out=gcm -Module $_.name -CommandType cmdlet, function | select name; if ($out -eq $NULL){write "`tERROR: Module Not loaded"; $import= read-host -prompt "Do You want to import $_ ? [yes/no]"; if ($import -imatch "yes"){ipmo $_ ; gcm -Module $_ -CommandType cmdlet, function | select name}}else{$out}}

  12. Krunch {The Commenter formerly known as K} says:

    @jrv I knew the second i posted that i would get a response from you.

    Version_2 (Now with useless whitespace):

    gmo -ListAvailable |

    %{"`r`nmodule name: $_"; "`r`n"

    $out=gcm -Module $_.name -CommandType cmdlet, function | select name

    if ($out -eq $NULL){

                                 write "`tERROR: Module Not loaded"

                                 $import= read-host -prompt "Do You want to import $_ ? [yes/no]"

                                             if ($import -imatch "yes"){

                                                                                  ipmo $_

                                                                                 gcm -Module $_ -CommandType cmdlet, function | select name                                 }

    }

    else {

    $out

     }

    }

  13. Me says:

    It's nice having these commands but it would be better if I knew what it was doing to get the output. I have no idea what any of the command after the "foreach" does

  14. Krunch {The Commenter formerly known as K} says:

    @Me

    I shall oblige.

    #list all modules

    gmo -ListAvailable |

    #foreach loop

    %{"`r`nmodule name: $_"; "`r`n"

    #the variable $out is getting the specified module's cmdlets and functions

    $out=gcm -Module $_.name -CommandType cmdlet, function | select name

    #First If statement looking for no output ($NULL) in the variable $out

    if ($out -eq $NULL){

                               #print to screen ERROR: Module Not loaded

                                write "`tERROR: Module Not loaded"

                                #print to the screen Do You want to import (module name)? [yes/no]

                                $import= read-host -prompt "Do You want to import $_ ? [yes/no]"

                                         #Second if statement looking for yes or Yes (the "i" in match is denoting case-insensitive)

                                            if ($import -imatch "yes"){

                                                                        # If the test is true (ie Yes) then the current module name is imported

                                                                                 ipmo $_

                                                                        #get the specified module's cmdlets and functions

                                                                                gcm -Module $_ -CommandType cmdlet, function | select name                                 }

    }

    #If statement false (ie No or N or anything other than yes or Yes) print what is in the variable $out

    else {

    $out

    #End the If statement (the first one not the nested one aka the second)

    }

    #End the foreach loop

    }

  15. Krunch {The Commenter formerly known as K} says:

    @sevengs

    "`r`nmodule name: $_"; "`r`n"

       # for more on special characters (get-help about_escape_characters -full | more)

    `r   escaped character denoting Carriage return

    `n  escaped character denoting New line

    $_  In the Foreach loop the name of the current module

    printing:

    #space

    #space

    module name: (module name)

    #space

    #space

  16. Krunch {The Commenter formerly known as K} says:

    @sevengs

    It is the responsibility of all those with knowledge to share it. A phrase I take to heart is "To be Knowledgeable, You Must First Be Ignorant". No need to thank.

    To find all the about Help files:

    get-help about_*

  17. Royston says:

    Stupidist question in the world: I loaded this function, when i run that expand-msgattachment * i get a blank return value? What or where should i be look/doing?

  18. Royston says:

    Guys, I just want to automatically extract attachments that come into a folder and then auto print them, i have a vb script that does that but wanted to use powershell going forward, any ideas on how to do this? obviously im a novice beginner but need
    this as a bespoke corporate solution

  19. kheg says:

    BEST THREAD EVER!!!
    i don’t even care about sorting commands anymore!

Skip to main content