{"id":493,"date":"2007-07-09T18:17:30","date_gmt":"2007-07-09T18:17:30","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/andrewarnottms\/2007\/07\/09\/getting-doskey-macros-to-work-in-powershell\/"},"modified":"2019-04-03T22:50:28","modified_gmt":"2019-04-04T05:50:28","slug":"getting-doskey-macros-to-work-in-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/premier-developer\/getting-doskey-macros-to-work-in-powershell\/","title":{"rendered":"Getting doskey macros to work in PowerShell"},"content":{"rendered":"<p>As much as I love to work with PowerShell, it was hard to give up the doskey macros I had defined for CMD.exe.&nbsp; But I just found out that doskey can work all its magic for PowerShell too, so here&#8217;s the trick&#8230;<\/p>\n<p>Doskey defaults to working only with cmd.exe, but by passing the \/exename= parameter to it, you can set macros for PowerShell as well.&nbsp; For example:<\/p>\n<p class=\"command\">PS&gt; doskey \/exename=powershell.exe cd\\home=pushd $env:USERPROFILE\\$*<\/p>\n<p>This effectively commandeers any command-line instruction beginning with &#8220;cd\\home&#8221; and expands it to &#8220;$env:USERPROFILE\\&#8221;, appending any &#8216;parameters&#8217; after &#8220;cd\\home&#8221; to the end.&nbsp; <\/p>\n<p>If you already have a text file of macros defined that you&#8217;re used to reading in using:<\/p>\n<p class=\"command\">CMD.exe C:\\&gt; doskey \/MACROFILE=mymacros.txt<\/p>\n<p>The following syntax should work:<\/p>\n<p class=\"command\">PS&gt; doskey \/exename=powershell.exe \/MACROFILE=mymacros.txt&nbsp; # Slow down there, Turbo!<\/p>\n<p>You shouldn&#8217;t run and add the \/exename=powershell.exe parameter just yet.&nbsp; You should go through your macros.txt file and review it for any syntax changes you need to make for PowerShell.&nbsp; For example, your macros.txt file may contain the following line:<\/p>\n<p>cd\\home=%USERPROFILE%\\$*<\/p>\n<p>But this line will need to be changed to<\/p>\n<p>cd\\home=$env:USERPROFILE\\$*<\/p>\n<p>Once you&#8217;ve converted your cmd.exe syntax to Windows PowerShell syntax, you should be good to go.<\/p>\n<p>On more thing.&nbsp; Some of you may be thinking &#8220;sure you can use doskey macros, but you <em>should<\/em> take advantage of PowerShell&#8217;s unique alias and function facilities.&#8221;&nbsp; And you&#8217;d be right &#8212; except that doskey macros allows for some macro names that PowerShell aliases and functions do not allow.&nbsp; For example, try writing a function or alias named &#8220;cd\\home&#8221; in PowerShell.&nbsp; Of course you can&#8217;t. But doskey macros make it work even in PowerShell.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As much as I love to work with PowerShell, it was hard to give up the doskey macros I had defined for CMD.exe.&nbsp; But I just found out that doskey can work all its magic for PowerShell too, so here&#8217;s the trick&#8230; Doskey defaults to working only with cmd.exe, but by passing the \/exename= parameter [&hellip;]<\/p>\n","protected":false},"author":2685,"featured_media":37840,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[4617,102],"class_list":["post-493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-permierdev","tag-andarno","tag-powershell"],"acf":[],"blog_post_summary":"<p>As much as I love to work with PowerShell, it was hard to give up the doskey macros I had defined for CMD.exe.&nbsp; But I just found out that doskey can work all its magic for PowerShell too, so here&#8217;s the trick&#8230; Doskey defaults to working only with cmd.exe, but by passing the \/exename= parameter [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/users\/2685"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/comments?post=493"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/493\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media\/37840"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media?parent=493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/categories?post=493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/tags?post=493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}