Naming clashes are something I expect to increase in frequency when PowerShell starts to be used more widely. I thought I would show you how to solve some categories of naming clashes. I will deal here with some of the situations that can arise when naming functions using names similar to cmdlets, that is verb-noun.

The situation can, potentially, become really complex so I will deal in this post only with some simple situations.

The name of a function can clash with an existing alias or cmdlet name. As an example consider what happens if you have written a function called rename-item. If you've been reading recent posts on this blog you will know that PowerShell has a rename-item cmdlet.

Assume that you have opened a fresh PowerShell console window.

If you type rename-item at the command line then you see a prompt

PS C:\> rename-item

cmdlet rename-item at command pipeline position 1
Supply values for the following parameters:

PowerShell prompts you to supply a value for the Path parameter.

Press Ctrl+C to stop this.

At the command line type the following to create the rename-item function:

function rename-item{

write-host "This output is from the rename-item function"


Then type at the command line:


You will see an appearance like this:

PS C:\> rename-item
This output is from the rename-item function
PS C:\>

By creating a function called rename-item you have, effectively, blocked execution of the rename-item cmdlet at the command line.

Why does this happen? PowerShell attempts to find an executable to match a command in the following order:

  1. Aliases
  2. Functions
  3. Cmdlets
  4. Executables
  5. Scripts
  6. Normal files

So when you created the rename-item function it takes precedence over the rename-item cmdlet.

If you want to be sure to have access to the rename-item cmdlet avoid creating a global function with that name since the function will always have higher priority than the cmdlet.

If you've been using Monad betas before the release of PowerShell RC1 you quite possibly have a significant number of scripts that you wrote using the Monad betas. Those files will have a .msh file extension. When you upgrade to PowerShell, apart from any changes you need to make to the content, you need to change the file extension to .ps1.

In the good old Windows command shell, doing that is straightforward. Simply navigate to the folder holding the scripts. Then use the following command:

ren *.msh *.ps1

If you try that with Monad you receive the following error:

PS C:\PowerShellScripts> ren *.msh *.ps1
Rename-Item : Cannot process argument because the value of argument "path" is invalid. At line:1 char:4
+ ren <<<< *.msh *.ps1

So, what's wrong with the path? To figure that out I will show the command in a full form:

ren -Path *.msh -NewName *.ps1

The error relates to the value of the Path parameter. It accepts wildcards in the path but it must resolve to a single file.

So how do you use PowerShell to rename multiple files?

PowerShell is designed to use pipelines. And you need a two step pipeline to get the job done. Assuming you are in the directory that contains the files that you want to rename, use the following command:

get-childitem -Path *.msh |

rename-item -NewName {$ -replace ".msh",".ps1"} -whatif

As you can see it's a pipeline with two steps. The first step uses the get-childitem cmdlet to retrieve information about all files in the current folder with a .msh file extension. The second step uses the rename-item cmdlet to process each object passed on from the first step. Each object is a FileInfo object. The value of the Extension property of each FileInfo object is .msh, as you can see by using the following command:

get-childitem *.msh |

format-table Name, Extension

The value of the NewName parameter is {$ -replace ".msh",".ps1"}. Any occurrence of .msh in the value of the Name property of the current object is replaced by .ps1.

To put it more succinctly, all files with a file extension of .msh are renamed to have a file extension of .ps1.

In Windows Explorer you can rename the current folder. The rename-item cmdlet doesn't allow you to rename any folder.

The example I showed used the FileSystem provider. You can use the rename-item cmdlet to rename items in other providers, for example the alias and variable providers. To display available providers use this command:


The get-PSDrive cmdlet has replaced the get-drive cmdlet which was found in public builds before RC1.