How do I retrieve the available commands from a module?

旧时模样 提交于 2019-11-27 11:38:21

问题


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?


回答1:


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>



回答2:


Use the parameter -ListAvailable

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

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




回答3:


PowerShell 2.0 - this works for me:

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

To list the loaded modules in the current session:

Get-Module


来源:https://stackoverflow.com/questions/6354317/how-do-i-retrieve-the-available-commands-from-a-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!