Renaming multiple file extensions using Powershell

Heyas,

How do rename all .csv files in a directory to .xls using PowerShell, preserving the filename of course?

I found this command: Get-ChildItem -Filter “*csv*” -Recurse | Rename-Item -NewName {$_.name -replace ‘csv’,’xls’ }

But I want to make sure only the file extension part of the file is changed.

Any assistance is appreciated.

Using powershell v3 on the server.

Thank you
ZackGeneral IT Goto GuyAsked:
Who is Participating?
 
oBdAConnect With a Mentor Commented:
This is in test mode and will only display what it would do normally. Remove the "-WhatIf" at the end to run it for real.
Get-ChildItem -Filter "*.csv" -Recurse | % {Rename-Item -Path $_.FullName -NewName ($_.BaseName + '.xls') -WhatIf}

Open in new window

0
 
Mal OsborneAlpha GeekCommented:
From a boring old DOS prompt, REN *.csv *.xls will do that. Pretty sure this works in exactly the same way from within Powershell.
0
 
ZackGeneral IT Goto GuyAuthor Commented:
Hi Malemsa,

I need a PowerShell version of this I am been tasked with modifying PowerShell job in Task Scheduler.

Thank you.
0
 
ZackGeneral IT Goto GuyAuthor Commented:
Thank you for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.