PowerShell Cookbook

Search

Categories

 

On this page

Archive

Blogroll

Disclaimer
I work for Microsoft.

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 220
This Year: 20
This Month: 0
This Week: 0
Comments: 533

Sign In

 Saturday, October 21, 2006
Sunday, October 22, 2006 1:40:44 AM (Pacific Daylight Time, UTC-07:00) ( )

To give a glimpse into the writing process behind my upcoming "Windows PowerShell - The Definitive Guide" (O'Reilly,) I'll occasionally post entries "as the author sees it."  The first in this series shows how to search the PowerShell help content for a phrase or pattern.

 

Program: Get-HelpMatch¶

Both the Get-Command and Get-Help cmdlets allow you to search for command names that match a given pattern. However, when you don't know exactly what you are looking for, you will more often have success searching through the help content for an answer. On Unix systems, this command is called Apropos.  Similar functionality does not exist as part of the PowerShell's help facilities, however.¶

That doesn't need to stop us, though, as we can write the functionality ourselves.¶

To run this program, supply a search string to the Get-HelpMatch script. The search string can be either simple text, or a regular expression. The script then displays the name and synopsis of all help topics that match. To see the help content for that topic, use the Get-Help cmdlet.¶

Example 1-4. Get-HelpMatch.ps1¶

##############################################################################¶

## Get-HelpMatch.ps1¶

##¶

## Search the PowerShell help documentation for a given keyword or regular¶

## expression.¶

## ¶

## Example:¶

##    Get-HelpMatch hashtable¶

##    Get-HelpMatch "(datetime|ticks)"¶

##############################################################################¶

 ¶

param($searchWord = $(throw "Please specify content to search for"))¶

 ¶

$helpNames = $(get-help *)¶

 ¶

foreach($helpTopic in $helpNames)¶

   $content = get-help -Full $helpTopic.Name | out-string¶

   if($content -match $searchWord)¶

  

      $helpTopic | select Name,Synopsis¶

  

 

Thursday, January 18, 2007 4:20:51 PM (Pacific Standard Time, UTC-08:00)
Thanks for this useful script.
Peter Tagaropulous
Name
E-mail
Home page

Comment (Some html is allowed: b, blockquote@cite, em, i, strike, strong, sub, super, u)  

Enter the code shown (prevents robots):