{"id":82,"date":"2007-02-27T12:00:00","date_gmt":"2007-02-27T20:00:00","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2007\/02\/27\/fast-furious-powershell-find-that-function\/"},"modified":"2007-02-27T12:00:00","modified_gmt":"2007-02-27T20:00:00","slug":"fast-furious-powershell-find-that-function","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2007\/02\/27\/fast-furious-powershell-find-that-function\/","title":{"rendered":"Fast &#038; Furious PowerShell: Find that Function"},"content":{"rendered":"<p>Like my <a href=\"\/current\/2007\/2\/26\/fast-furious-powershell-unmask-the-alias.html\">recent post<\/a> about the Alias provider.&nbsp; There is also a Function provider. You can use basically the same techniques that I used to explore aliases.<\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">dir function:<\/font><\/p>\n<p>Gives you basic information.&nbsp; I like this:<\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">dir function: | select name,definition |format-table -auto<\/font><\/p>\n<p>because I can see more of the definition.&nbsp; Even&nbsp;better, for each function name I can do something like this:<\/p>\n<p><font size=\"2\" face=\"Lucida console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">PS E:\\ &gt; (dir function:edit-file).definition<br \/>param([string]$path) $editor = &#8220;notepad.exe&#8221;<br \/>if ($PscxTextEditorPreference -ne $null -and $PscxTextEditorPreference.Length -gt 0)<br \/>{<br \/>Get-Command $PscxTextEditorPreference 2&gt;&amp;1 | out-null<br \/>if ($?) {<br \/>$editor = $PscxTextEditorPreference<br \/>}<br \/>} <\/font><\/p>\n<p><font size=\"2\" face=\"Lucida console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">&amp; $editor $path<\/font> <\/p>\n<p>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: <\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">PS E:\\ &gt; foreach ($item in (dir function:)) { write-host -back yellow -fore Blue $item.name;$item.definition}<\/font> <\/p>\n<p>Isn&#8217;t&nbsp;this fun? <\/p>\n<\/p>\n<div style=\"margin: 0px; padding: 0px; display: inline; float: none;\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:a110e916-d9d3-46dc-8107-3ea9090e17da\" class=\"wlWriterSmartContent\">Technorati tags: <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/PowerShell\">PowerShell<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/Scripting\">Scripting<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/Functions\">Functions<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/Get-ChildItem\">Get-ChildItem<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/Provider\">Provider<\/p>\n<p><\/a><\/div>\n<div style=\"margin: 0px; padding: 0px; display: inline;\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:a7ad6a6c-4387-47dc-8fb4-e8835e089649\" class=\"wlWriterSmartContent\">del.icio.us tags: <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/PowerShell\">PowerShell<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/Scripting\">Scripting<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/Functions\">Functions<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/Get-childitem\">Get-childitem<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/Provider\">Provider<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n<p>dir function:<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[],"class_list":["post-82","post","type-post","status-publish","format-standard","hentry","category-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/82","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=82"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/82\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=82"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=82"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=82"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}