Fast & Furious PowerShell: Find that Function

Like my recent post about the Alias provider.  There is also a Function provider. You can use basically the same techniques that I used to explore aliases.

dir function:

Gives you basic information.  I like this:

dir function: | select name,definition |format-table -auto

because I can see more of the definition.  Even better, for each function name I can do something like this:

PS E:\ > (dir function:edit-file).definition
param([string]$path) $editor = “notepad.exe”
if ($PscxTextEditorPreference -ne $null -and $PscxTextEditorPreference.Length -gt 0)
{
Get-Command $PscxTextEditorPreference 2>&1 | out-null
if ($?) {
$editor = $PscxTextEditorPreference
}
}

& $editor $path

Unlike Alias, there is no Get-Function cmdlet, so this is an easy way to discover the code behind a given function. Finally, here is the uber-command to enumerate all functions and their definitions:

PS E:\ > foreach ($item in (dir function:)) { write-host -back yellow -fore Blue $item.name;$item.definition}

Isn’t this fun?