74

To know which PowerShell modules are available on a machine I use the command

Get-Module -ListAvailable

This returns a list with module-type, -name and the exported commands. But the exported commands are always empty and just displaying {}. Why is this not displayed?

Do I have to use another parameter or is there another cmdlet or method to retrieve the available commands?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tom
  • 1,611
  • 1
  • 13
  • 16

5 Answers5

122

Exported commands are not available if the module is not loaded. You need to load the module first and then execute Get-Command:

Import-Module -Name <ModuleName>
Get-Command -Module <ModuleName>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Shay Levy
  • 121,444
  • 32
  • 184
  • 206
20

Use the parameter -ListAvailable

Get-Module <moduleName> -ListAvailable | % { $_.ExportedCommands.Values }

"<moduleName>" is optional. Omit to show all available modules.

JamesThomasMoon
  • 6,169
  • 7
  • 37
  • 63
Pedro Casalinho
  • 301
  • 2
  • 5
  • 4
    Welcome to Stack Overflow! While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations. – FelixSFD Nov 23 '16 at 12:06
  • 1
    My question is a bit outdated. But your reply does not work for powershell 2 because the property "ExportedCommands" is empty. Your code works properly for powershell 4 and 5. – Tom Jan 13 '17 at 09:43
1

[enter image description here][1]In the meantime this command here answers the question:

Get-Command -Module <#Your Module#>

Pretty simple...

Here the Output: https://i.stack.imgur.com/bITl0.jpg

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – another victim of the mouse May 12 '22 at 18:43
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/31747961) – ryanwebjackson May 16 '22 at 12:01
0

This will List all the commands under a module and search through them:

Get-Command -Module dbatools| ?{$_.name -match 'service'}
SAKA UK
  • 39
  • 4
-1

PowerShell 2.0 - this works for me:

Get-Module <moduleName> | % {$_.ExportedCommands.Values}

To list the loaded modules in the current session:

Get-Module
Community
  • 1
  • 1
user1390375
  • 676
  • 6
  • 5