I have a group of pictures (.jpg) all in the same folder that are all named something different. I am trying to rename all of them to the same name, numbered consecutively like it would in file explorer. EX. Test.jpg, Test(1).jpg Test(2) and so on.

This is what I have been trying but it tells me 'cannot create a file when that file already exists' and only changes the name of one file.

Get-ChildItem | Rename-Item -newname { 'Test.jpg' } 

I am hoping some could show me a way to get it to number them like above. Thanks For All Help In Advance.

  • not exactly what you want but still doing the trick: $i = 0 ; $x = gci . | % { $i++ ; Rename-Item $_ "Test($i).jpg" } basically you loop over each file and for each loop you set $i + 1 and then use it in your rename-item
    – SimonS
    Apr 3, 2017 at 13:05
  • Well instead of simulating explorer behavior, you could use explorer ui
    – LotPings
    Apr 3, 2017 at 13:15

1 Answer 1


You can achieve something like this with a loop.

First you get the content of your folder and save that in a variable:

$Content = Get-ChildItem -Path "C:\path\targetfolder"

Then, since you want to edit the whole content, you can use a "foreach" loop. And for the incrementing number just add a little integer variable to it. So something like this:

$n = 0

foreach($Content in $Content)
    Rename-Item -Path "C:\path\targetfolder\$Content" -NewName "test$n.jpg"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .