One step better than get-command
Published Nov 05 2007 02:00 PM 1,410 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 } |%{$_.name}) -like $n };       foreach ($cmd1 in $cmdarray)       {             $cmd1.name;             "---------";             ($cmd1.parametersets| %{$_.parameters } |%{$_.name}) -like $n | sort -unique;             ""       } } findparams($arg) - Scott Landry

1 Comment
Version history
Last update:
‎Nov 05 2007 02:00 PM
Updated by: