-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathGetFunction.ps1
26 lines (19 loc) · 973 Bytes
/
GetFunction.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
Function Get-Function ([string]$Pattern, [string]$Path="$pwd") {
$parser = [System.Management.Automation.PSParser]
$(ForEach( $file in Get-ChildItem $Path -Recurse -Include *.ps1, *.psm1) {
$content = [IO.File]::ReadAllText($file.FullName)
$tokens = $parser::Tokenize($content, [ref] $null)
$count = $tokens.Count
for($idx=0; $idx -lt $count; $idx += 1) {
if($tokens[$idx].Content -eq 'function') {
$targetToken = $tokens[$idx+1]
New-Object PSObject -Property @{
FileName = $file.FullName
FunctionName = $targetToken.Content
Line = $targetToken.StartLine
} | Select FunctionName, FileName, Line
}
}
}) | Where {$_.FunctionName -match $Pattern}
}
Get-Function -Path $PSHOME\Modules\PSDiagnostics | Out-GridView