PowerTip: Display All PowerShell Modules and Cmdlets

PowerTip: Display All PowerShell Modules and Cmdlets

  • Comments 16
  • Likes

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}

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

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

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

     }

    }

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

  • Useful...

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

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

  • 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

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

    }

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

                   }

       }

  • if($out -eq $NULL)

    IS REDUNDANT AND KLUNKY.

    if(!$out){ ... }

    Much more PowerShell-like.  It also reads better.

  • 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..

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

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

    Can someone explain this bit?

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

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

  • 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 :D

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

  • @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_*