Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I retrieve the available commands from a module?

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?

like image 356
Tom Avatar asked Jun 15 '11 07:06

Tom


People also ask

How do I get commands from a PowerShell Module?

Get-Command gets the commands from PowerShell modules and commands that were imported from other sessions. To get only commands that have been imported into the current session, use the ListImported parameter. Without parameters, Get-Command gets all of the cmdlets, functions, and aliases installed on the computer.

What is the command to list available modules?

List all available modules by executing " module avail " command. The results are a list of module names that can be loaded.

How can you get a list of all available modules on your computer?

To see all modules installed on the system, use the Get-Module -ListAvailable command.


2 Answers

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> 
like image 160
Shay Levy Avatar answered Sep 22 '22 21:09

Shay Levy


Use the parameter -ListAvailable

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

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

like image 23
user2095160 Avatar answered Sep 23 '22 21:09

user2095160