Where do the functions come from?

August 17, 2009

no comments

With PowerShell 2.0 you can tell exactly where a function came from, whether the function was defined in your profile or dot-sourced in a script file. You may find it useful when you want to edit a function source code but don’t know or remember the function source file. 

The one-liner below gets all functions from the built-in Function provider (contains a view of the functions stored in session state), filters just those that have a value in the ScriptBlock.File member and creates a new calculated property to display the location of the file the function came from.

Get-ChildItem Function: | Where-Object {$_.ScriptBlock.File} | Select-Object Name,@{Name="Location";Expression={$_.ScriptBlock.File}}

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*