Welcome to Exchange Team Blog Sign in | Join | Help

Syndication

This Blog

One step better than get-command

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

Share this post :
Published Monday, November 05, 2007 11:00 AM by Exchange
Filed Under: , ,

Comments

 

Kirk Munro said:

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.
November 20, 2007 5:01 PM
New Comments to this post are disabled

News


This blog and its contents are provided "AS IS" with no warranties, and they confer no rights. Use of any included script samples are subject to the terms specified in the Terms of Use.
New! Would you like to suggest a topic for the Exchange team to blog about? Send suggestions to us.

Exchange Server 2010 - Get the Release Candidate



Poll:

Other Exchange Blogs from MSFT