Skip navigation

Dealing with Cmdlet Name Conflicts


What would happen if you attempted to load a module that contained a function named Get-ChildItem? Keep in mind that Get-ChildItem is a core PowerShell cmdlet, so it already exists. When I ran Get-ChildItem, the function, rather than the built-in command, would run. I could still access the built-in command like this:

microsoft.powershell.management\get-childitem

That's pretty awkward, but there's actually a very cool reason for this: It means I can "overwrite" PowerShell's own core functionality. In a future article, I'll write about "proxy functions," which can do some pretty amazing stuff.

This business with name conflicts is one reason you'll usually see cmdlet authors add a short prefix to the noun portion of their cmdlet name. You don't get "Get-User," you get "Get-ADUser," tying the cmdlet to a specific technology (AD) and helping to avoid conflicts with other "user" related cmdlets that you might need to load into the shell.

Want to ask a question about this article? I'll answer at http://powershell.com/cs/forums/230.aspx!




Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish