'man -k' for Powershell

  • strict warning: Non-static method view::load() should not be called statically in /hermes/walnaweb12a/b57/moo.greydragoncom/nodsw/sites/all/modules/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /hermes/walnaweb12a/b57/moo.greydragoncom/nodsw/sites/all/modules/views/handlers/views_handler_argument.inc on line 744.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /hermes/walnaweb12a/b57/moo.greydragoncom/nodsw/sites/all/modules/views/handlers/views_handler_filter.inc on line 607.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /hermes/walnaweb12a/b57/moo.greydragoncom/nodsw/sites/all/modules/views/handlers/views_handler_filter.inc on line 607.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /hermes/walnaweb12a/b57/moo.greydragoncom/nodsw/sites/all/modules/views/handlers/views_handler_filter_boolean_operator.inc on line 159.
Leeland's picture

Coming from Unix/Linux programming trying to get stuff done on Windows is sometimes worse than getting teeth pulled. Powershell has definitely improved things, however, Powershell can be a bit obtuse. For example about 70% of the time there is already a command-let to do just what I want. But, just finding if there is a command-let has been painful. Today is no exception. (For those in a hurry the answer is Get-Command, for everyone else read on.)

I have seen in a number of blogs the expression "if only Powershell had something like Linux's 'man -k' or apropos commands." So this morning I went looking again. After a lot of Googling (which is normal for trying to find out how to do something that should be bloody simple but because of the object interface in Powershell is not) I found nothing specific. But, I got some whiffs of a possible solution.

A few minutes of experimenting with Powershell and I finally found the answer. It is the command-let Get-Command (why not just use Get-Help? Well that would break the designer's purist attitude of command-lets doing specific tasks and no more). Command-let naming is supposed to be broken down to "Verb-Noun" sequences. If you follow this pattern for your function names and personal scripts you'll have a smoother ride in Powershell.

So the command-let Get-Command will let you search for functions or applications which meet your criteria. It will even search for matches of types Alias, Application, Cmdlet, ExternalScript, Filter, and Script. That about covers the gambit of possibilities. You can limit your search or not. It does a nice job of breaking it down for you. It also uses the arguments -Name, -Verb, and -Noun for searching the whole name, before the dash, or after the dash in the name. It supports wild cards, so if no wildcard is used it means an exact match.

Here are some example uses:

> Get-Command -Name *Encod*

CommandType     Name                                                Definition
-----------     ----                                                ----------
Function        ConvertFrom-Base64EncodedString                     param([string]$dataToConvert)...
Function        ConvertFrom-UrlEncodedString                        param([string]$dataToConvert)...
Function        ConvertHashtableTo-UrlEncodedParameterString        param([hashtable]$dataToConvert)...
Function        ConvertTo-Base64EncodedString                       param([string]$dataToConvert)...
Function        ConvertTo-UrlEncodedString                          param([string]$dataToConvert)...
Application     uuencode.exe                                        C:\GnuWin32\bin\uuencode.exe
Application     WMVENCOD.DLL                                        C:\Windows\system32\WMVENCOD.DLL

> Get-Command -Verb ConvertFrom

CommandType     Name                                                Definition
-----------     ----                                                ----------
Function        ConvertFrom-Base64EncodedString                     param([string]$dataToConvert)...
Cmdlet          ConvertFrom-Csv                                     ConvertFrom-Csv [-InputObject]  [[-D...
Cmdlet          ConvertFrom-SecureString                            ConvertFrom-SecureString [-SecureString]  [-...
Function        ConvertFrom-UrlEncodedString                        param([string]$dataToConvert)...

> Get-Command -Noun XML

CommandType     Name                                                Definition
-----------     ----                                                ----------
Cmdlet          ConvertTo-Xml                                       ConvertTo-Xml [-InputObject]  [-Depth ...
Function        Parse-XML                                           param([string] $XMLString, [String] $XPath, [int...
Cmdlet          Select-Xml                                          Select-Xml [-XPath]  [-Xml]  ...

That should be enough to get you off the starting line. Happy Powershelling.

Thread Slivers eBook at Amazon