# encoding: ascii
# api: powershell
# title: Search-Help.ps1
# description: From Windows PowerShell Cookbook (O’Reilly) by Lee Holmes
# version: 0.1
# author: Lee Holmes
# license: CC0
# x-poshcode-id: 2208
# x-archived: 2016-03-18T23:49:41
# x-published: 2011-09-09T21:42:00
#
#
##############################################################################
##
## Search-Help
##
## From Windows PowerShell Cookbook (O'Reilly)
## by Lee Holmes (http://www.leeholmes.com/guide)
##
##############################################################################
<#
.SYNOPSIS
Search the PowerShell help documentation for a given keyword or regular
expression.
.EXAMPLE
Search-Help hashtable
Searches help for the term 'hashtable'
.EXAMPLE
Search-Help "(datetime|ticks)"
Searches help for the term datetime or ticks, using the regular expression
syntax.
#>
param(
## The pattern to search for
[Parameter(Mandatory = $true)]
$Pattern
)
Set-StrictMode -Version Latest
$helpNames = $(Get-Help * | Where-Object { $_.Category -ne "Alias" })
## Go through all of the help topics
foreach($helpTopic in $helpNames)
{
## Get their text content, and
$content = Get-Help -Full $helpTopic.Name | Out-String
if($content -match "(.{0,30}$pattern.{0,30})")
{
$helpTopic | Add-Member NoteProperty Match $matches[0].Trim()
$helpTopic | Select-Object Name,Match
}
}