-
Notifications
You must be signed in to change notification settings - Fork 2
/
Search-StartMenu.ps1
56 lines (43 loc) · 1.71 KB
/
Search-StartMenu.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
##############################################################################
##
## Search-StartMenu
##
## From Windows PowerShell Cookbook (O'Reilly)
## by Lee Holmes (http://www.leeholmes.com/blog)
##
##############################################################################
<#
.SYNOPSIS
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.
.EXAMPLE
PS > Search-StartMenu "Character Map" | Invoke-Item
Searches for the "Character Map" appication, and then runs it
PS > Search-StartMenu PowerShell | Select-FilteredObject | Invoke-Item
Searches for anything with "PowerShell" in the application name, lets you
pick which one to launch, and then launches it.
#>
param(
## The pattern to match
[Parameter(Mandatory = $true)]
$Pattern
)
Set-StrictMode -Version 3
## Get the locations of the start menu paths
$myStartMenu = [Environment]::GetFolderPath("StartMenu")
$shell = New-Object -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 in "my start menu" for text in the link name or link destination
dir $myStartMenu *.lnk -rec | Where-Object {
($_.Name -match "$escapedMatch") -or
($_ | Select-String "\\[^\\]*$escapedMatch\." -Quiet)
}
## Search in "all start menu" for text in the link name or link destination
dir $allStartMenu *.lnk -rec | Where-Object {
($_.Name -match "$escapedMatch") -or
($_ | Select-String "\\[^\\]*$escapedMatch\." -Quiet)
}