Get definition of function and echo the code
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
(Get-Command Test).Definition
That is how I normally get definitions.
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 this code:
$metadata = New-Object system.management.automation.commandmetadata (Get-Command Get-EventLog)
[System.management.automation.proxycommand]::Create($MetaData) | out-file C:\Get-EventLog.ps1