Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've defined a dynamic function in powershell, like this:

> function test { dir -r -fil *.vbproj | ft directory, name }

Then I can just type test and run that function, piping it to other commands, etc. Pretty handy.

Is there a way I can get the definition of the command? Can I echo out the code for my function test? (Without having to go back through my history to where I defined it?)

share|improve this question
up vote 8 down vote accepted

For a function called test:

$function:test

Or if the function name contains a hyphen (eg. test-function):

${function:test-function}

Alternatively:

(Get-Command test).Definition
share|improve this answer
(Get-Command Test).Definition

That is how I normally get definitions.

share|improve this answer

The current answers will only work for functions that have been created locally. You can, for example, see the definition of native functions like Get-EventLog.

For a list of all the available functions, you can run:

Get-ChildItem Function::

Any of these can be passed into ${function:myFn} or (Get-Command myFn).Definition

If you want to peek at native functions, you can run [the following code][1:

$metadata = New-Object system.management.automation.commandmetadata (Get-Command Get-EventLog)
[System.management.automation.proxycommand]::Create($MetaData) | out-file C:\Get-EventLog.ps1
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .