Comments (2)
Function Get-ModuleCommand {
<#
.Synopsis
Get commands from specific module(s) or a list of modules
.DESCRIPTION
Retreive all module names or commands filtered by name and/or command name.
.PARAMETER Name
Use module name filter option to limit help information to specific module(s). Supports wildcards
.PARAMETER CommandName
Retreive comnmand information from all modules or from specifc module(s). Supports wildcards
.PARAMETER ListAvailable
Expand scope to include available modules (not only installed)
.EXAMPLE
Get-ModuleCommand -Name PSScriptTools
List all exported commands for the 'PSScriptTools' module
.EXAMPLE
Get-ModuleCommand -CommandName "*address*"
Get all coomands containing 'address' from installed modules
.EXAMPLE
Get-ModuleCommand -CommandName *clip* -ListAvailible
List all available modules with commands containing the string 'clip'.
.EXAMPLE
Get-ModuleCommand -Name "*PowerShell*" -ListAvailible
List all modules containing the name 'PowerShell'
.EXAMPLE
Get-ModuleCommand
List instelled modules
#>
[cmdletbinding(DefaultParameterSetName = "name")]
[Alias("gmh")]
[OutputType("ModuleCommand")]
Param(
[Parameter(
Position = 0,
HelpMessage = "The name of an installed/available module",
ValueFromPipelineByPropertyName
)]
[SupportsWildcards()]
[string]$Name,
[Parameter(
HelpMessage = "Command name to search for"
)]
[SupportsWildcards()]
[string]$CommandName,
[switch]$ListAvailable
)
Begin {
Write-Verbose "Starting $($MyInvocation.MyCommand)"
$PSBoundParameters.Add("ErrorAction", "stop")
#region local functions
function getModuleInfo {
[cmdletbinding()]
param(
$module,
$CommandName
)
Write-Verbose "Using version $($module.version)"
$cmds = @()
Write-Verbose "Getting exported functions"
$cmds += $module.Exportedfunctions.keys | Where-Object { $_ -like "$CommandName" } | Get-Command
Write-Verbose "Getting exported cmdlets"
$cmds += $module.Exportedcmdlets.keys | Where-Object { $_ -like "$CommandName" } | Get-Command
Write-Verbose "Found $($cmds.count) functions and/or cmdlets"
$out = foreach ($cmd in $cmds) {
Write-Verbose "Processing $($cmd.name)"
#get aliases, ignoring errors for those commands without one
$alias = (Get-Alias -Definition $cmd.Name -ErrorAction SilentlyContinue).name
#it is assumed you have updated help
[PSCustomObject]@{
PSTypeName = "ModuleCommand"
Name = $cmd.name
Alias = $alias
Verb = $cmd.verb
Noun = $cmd.noun
Synopsis = (Get-Help $cmd.name -ShowWindow:$false).synopsis.trim()
Type = $cmd.CommandType
Version = $cmd.version
Help = $cmd.HelpUri
ModuleName = $module.name
ModulePath = $module.Path
Compatible = $module.CompatiblePSEditions
PSVersion = $module.PowerShellVersion
}
} #foreach cmd
$out
}
#endregion
}
Process {
If ([string]::IsNullOrEmpty($Name) -and [string]::IsNullOrEmpty($CommandName)) {
if ($ListAvailable) {
$out = Get-Module -ListAvailable | ForEach-Object {
[PSCustomObject]@{
PSTypeName = "ModuleCommand"
Name = $_.name
Alias = ""
Verb = ""
Noun = ""
Synopsis = $_.Description
Type = $null
Version = $_.version
Help = $_.HelpInfoUri
ModuleName = "Available Modules"
ModulePath = $_.Path
Compatible = $_.CompatiblePSEditions
PSVersion = $_.PowerShellVersion
}
}
}
else {
$out = Get-InstalledModule | ForEach-Object {
[PSCustomObject]@{
PSTypeName = "ModuleCommand"
Name = $_.name
Alias = ""
Verb = ""
Noun = ""
Synopsis = $_.Description
Type = $null
Version = $_.version
Help = $_.HelpInfoUri
ModuleName = "Installed Modules"
ModulePath = $_.Path
Compatible = $_.CompatiblePSEditions
PSVersion = $_.PowerShellVersion
}
}
}
}
else {
if ([string]::IsNullOrEmpty($CommandName)) { $CommandName = "*" }
if ([string]::IsNullOrEmpty($Name)) { $Name = "*" }
if ($ListAvailable) {
$out = Get-Module -Name $Name -ListAvailable | ForEach-Object {
#We need to rebind to object (reason unknown!!)
getModuleInfo -module $_ -CommandName $CommandName
}
}
else {
$out = Get-Module -Name $Name | ForEach-Object {
getModuleInfo -module $_ -CommandName $CommandName
}
}
}
#display results sorted by name for better formatting
$out | Sort-Object -Property ModuleName, Name
}
End {
Write-Verbose "Ending $($MyInvocation.MyCommand)"
}
} #close function
Register-ArgumentCompleter -CommandName Get-ModuleCommand -ParameterName Name -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
(Get-Module -Name "$wordtoComplete*").name |
ForEach-Object {
# completion text,listitem text,result type,Tooltip
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
from psscripttools.
I'm not sure where to begin with this. I am inclined to close this as an issue. I am very happy to look at a PR if you want to update the command in this module.
from psscripttools.
Related Issues (20)
- Fix VSCode snippets HOT 1
- ConvertTo-AsciiArt fails HOT 1
- [Question] Mystical Test-WithCulture HOT 2
- Function "Get-FolderSizeInfo" can throw exception HOT 4
- [Bug]: Show-ANSISequence -Background includes foreground HOT 1
- [Request]: Get-FolderSizeInfo long file/folder names enabler HOT 13
- Add parameter to Get-TypeMember HOT 1
- Hide common .NET methods in Get-TypeMember HOT 2
- Add CimClass member command HOT 2
- Sort Get-ParameterInfo output HOT 1
- Get-CommandSyntax by provider HOT 1
- Get-GitSize failing to return a value. HOT 1
- [Bug]: Unable to install HOT 4
- [Bug]: Get-WindowsVersion/Get-WindowsVersionString on non-English based systems HOT 6
- [Bug]: Convert-EventLogRecord Fails to Parse Bits-Client XML due to Id value HOT 2
- [Bug]: Conflict with NTFSSecurity module causes PSScriptTools to fail to import HOT 2
- [Bug]: get-foldersize and user profile files HOT 8
- ANSI style on powershell 7 when PSStyle is defined HOT 2
- Get-PSUnique enhancement HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from psscripttools.