{"id":97235,"date":"2017-10-16T07:00:00","date_gmt":"2017-10-16T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=97235"},"modified":"2019-03-13T01:18:50","modified_gmt":"2019-03-13T08:18:50","slug":"20171016-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20171016-00\/?p=97235","title":{"rendered":"Nasty gotcha: Powershell aliases that match commands you might want to run"},"content":{"rendered":"<p>PowerShell has a bunch of aliases, but some of them collide with programs you might want to run. <\/p>\n<pre>\nPowerShell Get-Alias\n<\/pre>\n<p>will print all the aliases. These two conflict with programs that come with Windows: <\/p>\n<ul>\n<li>    <code>sc<\/code>: <code>Set-Content<\/code> vs. <code>sc.exe<\/code>     (service control) <\/li>\n<li>    <code>fc<\/code>: <code>Format-Custom<\/code> vs. <code>fc.exe<\/code>     (file compare) <\/li>\n<\/ul>\n<p>I&#8217;ve seen email threads where somebody says, for example, <\/p>\n<blockquote CLASS=\"q\">\n<p>Try running these commands: <\/p>\n<pre>\nsc stop someservice\nsome-command-to-reconfigure-the-service\nsc start someservice\n<\/pre>\n<\/blockquote>\n<p>and the other person says, &#8220;It doesn&#8217;t work.&#8221; When I run the second command, it says that it cannot reconfigure the service because it is already running.&#8221; <\/p>\n<p>Eventually, we figure out that the reason is that the other person uses PowerShell as their default command shell, and the command happens to collide with a PowerShell alias. What&#8217;s particularly devious is that <code>Set-Content<\/code> command is happy  to accept <code>start someservice<\/code> as its command line. It creates a text file called <code>start<\/code> with the contents <code>someService<\/code>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Because two-letter names would never collide, right?<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-97235","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Because two-letter names would never collide, right?<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=97235"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97235\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=97235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=97235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=97235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}