When working at the command line, you might want to launch a program that is normally found only on your Start menu. While you could certainly click through the Start menu to find it, you could also search the Start menu with a script, as shown in Example 144.
Example 144. SearchStartMenu.ps1
############################################################################## ## ## SearchStartMenu.ps1 ## ## Search the Start Menu for items that match the provided text. This script ## searches both the name (as displayed on the Start Menu itself,) and the ## destination of the link. ## ## ie: ## ## PS >SearchStartMenu "Character Map" | InvokeItem ## PS >SearchStartMenu "network" | SelectFilteredObject | InvokeItem ## ##############################################################################
param( $pattern = $(throw "Please specify a string to search for.") )
## Get the locations of the start menu paths $myStartMenu = [Environment]::GetFolderPath("StartMenu") $shell = NewObject Com WScript.Shell $allStartMenu = $shell.SpecialFolders.Item("AllUsersStartMenu")
## Escape their search term, so that any regular expression ## characters don't affect the search $escapedMatch = [Regex]::Escape($pattern)
## Search for text in the link name dir $myStartMenu *.lnk rec | ? { $_.Name match "$escapedMatch" } dir $allStartMenu *.lnk rec | ? { $_.Name match "$escapedMatch" }
## Search for text in the link destination dir $myStartMenu *.lnk rec | WhereObject { $_ | SelectString "\\[^\\]*$escapedMatch\." Quiet } dir $allStartMenu *.lnk rec | WhereObject { $_ | SelectString "\\[^\\]*$escapedMatch\." Quiet }