{"id":739,"date":"2014-09-04T00:01:00","date_gmt":"2014-09-04T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/09\/04\/powershell-naming-conflicts\/"},"modified":"2014-09-04T00:01:00","modified_gmt":"2014-09-04T00:01:00","slug":"powershell-naming-conflicts","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powershell-naming-conflicts\/","title":{"rendered":"PowerShell Naming Conflicts"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Learn how to handle naming conflicts for Windows PowerShell cmdlets.<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>&nbsp;Hey, Scripting Guy! My Windows PowerShell installation is completely hosted on my laptop. In fact, I tried to uninstall and reinstall Windows PowerShell, but that did not work. I really do not want to have to pave my laptop. I download this module from the Internet. It works really well, but the issue is that one of the cmdlets replaced one of the standard cmdlets on my computer. I really need to be able to use the standard cmdlet, and I do not know what to do. Help!<\/p>\n<p>&mdash;DV<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>&nbsp;Hello DV,<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. This morning I am sitting at my desk sipping a cup of English Breakfast tea with a bit of licorice root, peppermint herb, spearmint herb, and a cinnamon stick. It is quite refreshing, and delightful&mdash;especially because my arms feel like they are made from rubber. I just got back from the gym. (It is difficult to replace years of bad habits with a few weekly sessions at the gym, but it is also import to get started&mdash;and that is what I am doing.)<\/p>\n<h2>PowerShell cmdlet naming conflicts<\/h2>\n<p>Windows PowerShell is powerful and easy-to-use. It makes a lot of decisions for me. For example, if I import a module that has a cmdlet with the same name as an existing cmdlet, Windows PowerShell will use the new cmdlet. For example, let&#039;s say that I import a module named <b>Process<\/b><i>. <\/i>It has a function named <b>Get-Process<\/b>. When I type <b>Get-Process<\/b>, I get the results from that function. This is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-9-4-14-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-9-4-14-01.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>From this display, I see that I am not getting the normal output from the <b>Get-Process<\/b> cmdlet that I have used since Windows PowerShell&nbsp;1.0 came out. This is disappointing. So I use the <b>Get-Command<\/b> cmdlet to see what is going on. Here are the results:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-Command -Module Process<\/p>\n<p style=\"margin-left:30px\">CommandType&nbsp;&nbsp;&nbsp;&nbsp; Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ModuleName<\/p>\n<p style=\"margin-left:30px\">&#8212;&#8212;&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;-<\/p>\n<p style=\"margin-left:30px\">Function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-Process&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Process<\/p>\n<p>It seems that <b>Get-Process<\/b> has been replaced by a function with the same name. It is from a module named <b>Process<\/b><i>. <\/i><\/p>\n<p>I can unload that module by using the <b>Remove-Module<\/b> cmdlet as shown here:<\/p>\n<p style=\"margin-left:30px\">Remove-Module Process<\/p>\n<p><b>&nbsp; &nbsp;Note<\/b>&nbsp; Using <b>Remove-Module<\/b> only unloads the module from memory. It does not actually delete the module, nor does <br \/>&nbsp; &nbsp;it remove it from disk.<\/p>\n<p>Now if I use the <b>Get-Process<\/b> cmdlet, I see the standard output. This is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-9-4-14-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-9-4-14-02.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>But what if I want the commands that are available from the <b>Process<\/b><i> <\/i>module? How can I have access to those commands, and also access the standard <b>Get-Process<\/b> cmdlet? There are actually two ways to coexist&#8230;<\/p>\n<h2>Two ways to coexist<\/h2>\n<p>The first way to coexist (but by no means the easiest) is to reference the cmdlet by its complete name. This is the name of the module, separated by a backslash, and then the cmdlet name. To determine the cmdlet&rsquo;s module, use the <b>Get-Command<\/b> cmdlet. Here is an example:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-Command Get-Process | ft -AutoSize<\/p>\n<p style=\"margin-left:30px\">CommandType Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ModuleName<\/p>\n<p style=\"margin-left:30px\">&#8212;&#8212;&#8212;&#8211; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;-<\/p>\n<p style=\"margin-left:30px\">Cmdlet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-Process Microsoft.PowerShell.Management<\/p>\n<p>I see that the <b>Get-Process<\/b> cmdlet is in the Microsoft.PowerShell.Management module, so this is what I will need to type.<\/p>\n<p>I import the <b>Process<\/b><i> <\/i>module, check to ensure that the <b>Get-Process<\/b> cmdlet is overwritten, and then specify the complete name. It works:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Import-Module Process<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-Process | select -Last 1<\/p>\n<p style=\"margin-left:30px\">splwow64.exe<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Microsoft.PowerShell.Management\\Get-Process | select -Last 1<\/p>\n<p style=\"margin-left:30px\">Handles&nbsp; NPM(K)&nbsp;&nbsp;&nbsp; PM(K)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WS(K) VM(M)&nbsp;&nbsp; CPU(s)&nbsp;&nbsp;&nbsp;&nbsp; Id ProcessName<\/p>\n<p style=\"margin-left:30px\">&#8212;&#8212;-&nbsp; &#8212;&#8212;&nbsp;&nbsp;&nbsp; &#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211; &#8212;&#8211;&nbsp;&nbsp; &#8212;&#8212;&nbsp;&nbsp;&nbsp;&nbsp; &#8212; &#8212;&#8212;&#8212;&#8211;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; 1630&nbsp;&nbsp;&nbsp;&nbsp; 142&nbsp;&nbsp; 112116&nbsp;&nbsp;&nbsp;&nbsp; 154792&nbsp;&nbsp; 530&nbsp;&nbsp;&nbsp; 10.41&nbsp;&nbsp; 7044 WWAHost<\/p>\n<p><b>&nbsp; &nbsp;Note&nbsp;<\/b> Tab expansion does not work for module names when you are specifying the complete name. So it is helpful to <br \/>&nbsp; &nbsp;copy the module name to the Clipboard when looking it up via <b>Get-Command<\/b>.<\/p>\n<p>The second way to coexist is to specify a command prefix when you import the module. This will add a couple of letters to the noun name; therefore, it avoids the naming conflict. Here is an example:<\/p>\n<p>First I import the module, and specify the prefix. Then I use <b>Get-Command<\/b> to see the cmdlet name, and I use the new cmdlet name (<b>Get-edProcess<\/b>) to retrieve a single process name. This is shown here:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Import-Module Process -Prefix ed<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-Command -Module process<\/p>\n<p style=\"margin-left:30px\">CommandType&nbsp;&nbsp;&nbsp;&nbsp; Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ModuleName<\/p>\n<p style=\"margin-left:30px\">&#8212;&#8212;&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;-<\/p>\n<p style=\"margin-left:30px\">Function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-edProcess&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Process<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-edProcess | select -Last 1<\/p>\n<p style=\"margin-left:30px\">splwow64.exe<\/p>\n<p>Now I can use the standard cmdlet with the standard cmdlet name. Here, I retrieve a single process object:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-Process | select -Last 1<\/p>\n<p style=\"margin-left:30px\">Handles&nbsp; NPM(K)&nbsp;&nbsp;&nbsp; PM(K)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WS(K) VM(M)&nbsp;&nbsp; CPU(s)&nbsp;&nbsp;&nbsp;&nbsp; Id ProcessName<\/p>\n<p style=\"margin-left:30px\">&#8212;&#8212;-&nbsp; &#8212;&#8212;&nbsp;&nbsp;&nbsp; &#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211; &#8212;&#8211;&nbsp;&nbsp; &#8212;&#8212;&nbsp;&nbsp;&nbsp;&nbsp; &#8212; &#8212;&#8212;&#8212;&#8211;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; 1630&nbsp;&nbsp;&nbsp;&nbsp; 142&nbsp;&nbsp; 112116&nbsp;&nbsp;&nbsp;&nbsp; 154304&nbsp;&nbsp; 530&nbsp;&nbsp;&nbsp; 10.41&nbsp;&nbsp; 7044 WWAHost<\/p>\n<p>DV, that is all there is to handling Windows PowerShell naming conflicts. Join me tomorrow when I will talk about the Windows PowerShell Summit in Amsterdam.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to handle naming conflicts for Windows PowerShell cmdlets. &nbsp;Hey, Scripting Guy! My Windows PowerShell installation is completely hosted on my laptop. In fact, I tried to uninstall and reinstall Windows PowerShell, but that did not work. I really do not want to have to pave my laptop. I download this module from [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[51,3,4,45],"class_list":["post-739","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to handle naming conflicts for Windows PowerShell cmdlets. &nbsp;Hey, Scripting Guy! My Windows PowerShell installation is completely hosted on my laptop. In fact, I tried to uninstall and reinstall Windows PowerShell, but that did not work. I really do not want to have to pave my laptop. I download this module from [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=739"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/739\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}