One step better than get-command

Published Nov 05 2007 02:00 PM 1,262 Views

If you've spent any time in the PowerShell, then you're probably familiar with get-command (gcm). Here's an example I threw together taking that to the next level. This will help you when you can't remember the command you want to use. Say you want to find all shell commands that deal with DSNs but you can't remember the commands that deal with DSNs... [PS] C:\>findparams *DSN* New-SystemMessage --------- DsnCode Set-ForeignConnector --------- RelayDsnRequired Set-TransportConfig --------- GenerateCopyOfDSNFor Set-TransportServer --------- ExternalDelayDsnEnabled ExternalDsnDefaultLanguage ExternalDsnLanguageDetectionEnabled ExternalDsnMaxMessageAttachSize ExternalDsnReportingAuthority ExternalDsnSendHtml InternalDelayDsnEnabled InternalDsnDefaultLanguage InternalDsnLanguageDetectionEnabled InternalDsnMaxMessageAttachSize InternalDsnReportingAuthority InternalDsnSendHtml Please note that it only returns "new, set, and add" commands.  "get" commands do not return the parameters in the self-documenting help.  But if New-SystemMessage takes "DsnCode", you can assume that Get-SystemMessage will return it, or now that you know you want that you can do this: [PS] C:\>gcm -noun systemmessage CommandType     Name                            Definition -----------     ----                            ---------- Cmdlet          Get-SystemMessage               Get-SystemMessage [[-Identit... Cmdlet          New-SystemMessage               New-SystemMessage -DsnCode <... Cmdlet          Remove-SystemMessage            Remove-SystemMessage [-Ident... Cmdlet          Set-SystemMessage               Set-SystemMessage [-Identity... Ok, here's the nifty function you'll need to make this work. param([string]$arg) function findparams ($n) {       $cmdarray = get-command | ? { ($_.parametersets| %{$_.parameters } |%{$}) -like $n };       foreach ($cmd1 in $cmdarray)       {             $;             "---------";             ($cmd1.parametersets| %{$_.parameters } |%{$}) -like $n | sort -unique;             ""       } } findparams($arg) - Scott Landry

1 Comment
Not applicable
If your snapins have properly implemented PowerShell help, there is an easier way to do this out-of-the-box that doesn't seem to be very well known:

Get-Help * -Parameter *dsn*

This doesn't show you the parameter names that matched what you were looking for, but it does retrieve any cmdlets that have a parameter matching the string you enter without requiring an external function.  IMO this is usually sufficient to find what you were looking for and since it's built-in functionality it is easier to use.
Version history
Last update:
‎Nov 05 2007 02:00 PM
Updated by: