Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

3 Answers 3

up vote 7 down vote accepted

For a function called test:


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



(Get-Command test).Definition
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 (Get-Command Get-EventLog)
[]::Create($MetaData) | out-file C:\Get-EventLog.ps1
share|improve this answer
(Get-Command Test).Definition

That is how I normally get definitions.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.