{"id":81,"date":"2007-02-26T14:36:55","date_gmt":"2007-02-26T22:36:55","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2007\/02\/26\/fast-furious-powershell-unmask-the-alias\/"},"modified":"2007-02-26T14:36:55","modified_gmt":"2007-02-26T22:36:55","slug":"fast-furious-powershell-unmask-the-alias","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2007\/02\/26\/fast-furious-powershell-unmask-the-alias\/","title":{"rendered":"Fast &#038; Furious PowerShell: Unmask the alias"},"content":{"rendered":"<p>I&#8217;ve started using a lot of aliases in my PowerShell work. Many of them defined in my PowerShell profile. Unfortunately, I don&#8217;t always remember what I&#8217;ve defined, or even what the alias sometimes stands for. But with a few fast &amp; furious PowerShell expressions, I can strip away the mystery.<\/p>\n<p>Aliases are managed by the Alias provider. In PowerShell, that means I can use Get-ChildItem (or the DIR alias) and explore the alias provider just like a file system. Try this and you&#8217;ll see all the aliases on your system:<\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">dir alias: | format-table -auto<\/font><\/p>\n<p>I like to pipe output to format-table so I can see more of the definition.<\/p>\n<p>Want to see more detail about a specific alias?<\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">PS E:\\ &gt; dir-alias wd |format-list<\/font><\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">Name : wd<br \/>CommandType : Alias<br \/>Definition : E:\\Program Files\\Microsoft Office\\Office12\\winword.exe<br \/>ReferencedCommand : winword.exe<br \/>ResolvedCommand : winword.exe<\/font><\/p>\n<p>This is my shortcut to start Microsoft Word. The data is essentially the same thing you get by using Get-Alias.<\/p>\n<p>But what about an alias for a custom function? Works the same. I&#8217;ll use Get-Alias because it makes more sense:<\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">PS E:\\ &gt; get-alias du | format-table -auto <\/font><\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">CommandType Name Definition<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;<br \/>Alias&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; du&nbsp;&nbsp; Get-DiskUsage<\/font> <\/p>\n<p>But what is Get-DiskUsage? Easy enough to find.&nbsp; I need to check the ResolvedCommand property: <\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">PS E:\\ &gt; (get-alias du).ResolvedCommand | format-table -auto <\/font> <\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">CommandType Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Definition<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;&#8212;<br \/>Function&nbsp;&nbsp;&nbsp; Get-DiskUsage param( [string]$computer = &#8220;.&#8221; , [switch]$all)&nbsp;&#8230;<\/font> <\/p>\n<p>If I want to see the entire definition:<\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">PS E:\\ &gt; ((get-alias du).ResolvedCommand).Definition<br \/>param( [string]$computer = &#8220;.&#8221; , [switch]$all) $size = @{ l = &#8220;Size (MB)&#8221; e = { $_.size\/1mb}; f = &#8220;{0:N}&#8221;}<br \/>$free = @{ l = &#8220;free (MB)&#8221; e = { $_.freespace\/1mb}; f = &#8220;{0:N}&#8221;}<br \/>$perc = @{ l = &#8220;percent&#8221; e = { 100.0 * ([double]$_.freespace\/[double]$_.size)}; f=&#8221;{0:f}&#8221; }<br \/>$name = @{ e = &#8220;name&#8221; f = &#8220;{0,-20}&#8221; }<br \/>$fields = $name,$size,$free,$perc <\/font><\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\"># in case the user wants to see more than just local drives<br \/>$filter = &#8220;DriveType = &#8216;3&#8217;&#8221;<br \/>if ( $all ) { $filter = &#8220;&#8221; } <\/font> <\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\"># go do the work by getting the information from the appropriate<br \/># computer, and send it to format-table with the appropriate<br \/># fields and formatting info<br \/>get-wmiobject -class win32_logicaldisk -filter $filter -comp $computer |<br \/>format-table $fields -auto<\/font> <\/p>\n<p>The formatting may not be exactly right from copying and pasting but you get the idea. So, to wrap up, use this: <\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">dir alias: | select name,definition | format-table -auto<\/font> <\/p>\n<p>To get&nbsp;fast look at all your aliases. Finally, try this: <\/p>\n<p><font size=\"2\" face=\"Lucida Console\" color=\"#0000ff\" style=\"color: rgb(0, 0, 255);\">PS E:\\ &gt; foreach ($item in (dir alias:)) {write-host -back yellow -fore blue $item.name ; ((get-alias $item.name).ResolvedCommand).Definition}<\/font> <\/p>\n<p>By the way, instead of using MORE, you can click your mouse in the PowerShell console window and that should pause scrolling. Tap the space bar to resume. Send this output to a text file and you have a nice alias backup. <\/p>\n<\/p>\n<div style=\"margin: 0px; padding: 0px; display: inline;\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:a7fd64c4-3c8a-472b-97fd-fbb1f7d97cc2\" 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\/alias\">alias<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/Scripting\">Scripting<\/a>, <a rel=\"tag\" href=\"http:\/\/del.icio.us\/popular\/Get-ChildItem\">Get-ChildItem<\/a><\/div>\n<p>&nbsp;<\/p>\n<div style=\"margin: 0px; padding: 0px; display: inline;\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:7cf531e8-a25f-486e-af46-357046bbae32\" class=\"wlWriterSmartContent\">Technorati tags: <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/PowerShell\">PowerShell<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/alias\">alias<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/scripting\">scripting<\/a>, <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/Get-ChildItem\">Get-ChildItem<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve started using a lot of aliases in my PowerShell work. Many of them defined in my PowerShell profile. Unfortunately, I don&#8217;t always remember what I&#8217;ve defined, or even what the alias sometimes stands for. But with a few fast &#038; furious PowerShell expressions, I can strip away the mystery.<\/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-81","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\/81","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=81"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/81\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}