Home
%3CLINGO-SUB%20id%3D%22lingo-sub-590327%22%20slang%3D%22en-US%22%3EOne%20step%20better%20than%20get-command%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-590327%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20you've%20spent%20any%20time%20in%20the%20%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fpowershell%2F%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EPowerShell%3C%2FA%3E%2C%20then%20you're%20probably%20familiar%20with%20%3CA%20href%3D%22http%3A%2F%2Fwww.microsoft.com%2Ftechnet%2Fscriptcenter%2Ftopics%2Fwinpsh%2Fmanual%2Fstart.mspx%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Eget-command%3C%2FA%3E%20(gcm).%20Here's%20an%20example%20I%20threw%20together%20taking%20that%20to%20the%20next%20level.%20This%20will%20help%20you%20when%20you%20can't%20remember%20the%20command%20you%20want%20to%20use.%20Say%20you%20want%20to%20find%20all%20shell%20commands%20that%20deal%20with%20DSNs%20but%20you%20can't%20remember%20the%20commands%20that%20deal%20with%20DSNs...%20%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3E%5BPS%5D%20C%3A%5C%26gt%3Bfindparams%20*DSN*%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3ENew-SystemMessage%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3E---------%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EDsnCode%3C%2FSPAN%3E%20%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3ESet-ForeignConnector%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3E---------%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3ERelayDsnRequired%3C%2FSPAN%3E%20%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3ESet-TransportConfig%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3E---------%3C%2FSPAN%3E%20%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EGenerateCopyOfDSNFor%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3ESet-TransportServer%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3E---------%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EExternalDelayDsnEnabled%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EExternalDsnDefaultLanguage%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EExternalDsnLanguageDetectionEnabled%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EExternalDsnMaxMessageAttachSize%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EExternalDsnReportingAuthority%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EExternalDsnSendHtml%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EInternalDelayDsnEnabled%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EInternalDsnDefaultLanguage%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EInternalDsnLanguageDetectionEnabled%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EInternalDsnMaxMessageAttachSize%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EInternalDsnReportingAuthority%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3EInternalDsnSendHtml%3C%2FSPAN%3E%20Please%20note%20that%20it%20only%20returns%20%22new%2C%20set%2C%20and%20add%22%20commands.%26nbsp%3B%20%22get%22%20commands%20do%20not%20return%20the%20parameters%20in%20the%20self-documenting%20help.%26nbsp%3B%20But%20if%20New-SystemMessage%20takes%20%22DsnCode%22%2C%20you%20can%20assume%20that%20Get-SystemMessage%20will%20return%20it%2C%20or%20now%20that%20you%20know%20you%20want%20that%20you%20can%20do%20this%3A%20%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3E%5BPS%5D%20C%3A%5C%26gt%3Bgcm%20-noun%20systemmessage%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3ECommandType%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Definition%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3E-----------%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20----%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20----------%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3ECmdlet%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Get-SystemMessage%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Get-SystemMessage%20%5B%5B-Identit...%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3ECmdlet%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20New-SystemMessage%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20New-SystemMessage%20-DsnCode%20%26lt%3B...%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3ECmdlet%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Remove-SystemMessage%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Remove-SystemMessage%20%5B-Ident...%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%22%3ECmdlet%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set-SystemMessage%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set-SystemMessage%20%5B-Identity...%3C%2FSPAN%3E%20Ok%2C%20here's%20the%20nifty%20function%20you'll%20need%20to%20make%20this%20work.%20%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%3Bfont-size%3A%20small%22%3Eparam(%5Bstring%5D%24arg)%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%3Bfont-size%3A%20small%22%3Efunction%20findparams%20(%24n)%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%3Bfont-size%3A%20small%22%3E%7B%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%3Bfont-size%3A%20small%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24cmdarray%20%3D%20get-command%20%7C%20%3F%20%7B%20(%24_.parametersets%7C%20%25%7B%24_.parameters%20%7D%20%7C%25%7B%24_.name%7D)%20-like%20%24n%20%7D%3B%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%3Bfont-size%3A%20small%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20foreach%20(%24cmd1%20in%20%24cmdarray)%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%3Bfont-size%3A%20small%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%3Bfont-size%3A%20small%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24cmd1.name%3B%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%3Bfont-size%3A%20small%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22---------%22%3B%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%3Bfont-size%3A%20small%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20(%24cmd1.parametersets%7C%20%25%7B%24_.parameters%20%7D%20%7C%25%7B%24_.name%7D)%20-like%20%24n%20%7C%20sort%20-unique%3B%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%3Bfont-size%3A%20small%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22%22%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%3Bfont-size%3A%20small%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%3Bfont-size%3A%20small%22%3E%7D%20%3C%2FSPAN%3E%3CSPAN%20style%3D%22font-family%3A%20Courier%20New%3Bfont-size%3A%20small%22%3Efindparams(%24arg)%3C%2FSPAN%3E%20-%20Scott%20Landry%3C%2FP%3E%3C%2FLINGO-BODY%3E

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 } |%{$_.name}) -like $n };       foreach ($cmd1 in $cmdarray)       {             $cmd1.name;             "---------";             ($cmd1.parametersets| %{$_.parameters } |%{$_.name}) -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.