Solved

Renaming multiple file extensions using Powershell

Posted on 2016-11-29
4
37 Views
Last Modified: 2016-11-29
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
0
Comment
Question by:Zack
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Malmensa
ID: 41906714
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
 

Author Comment

by:Zack
ID: 41906731
Hi Malemsa,

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

Thank you.
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41906793
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
 

Author Closing Comment

by:Zack
ID: 41906801
Thank you for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
A brief introduction to what I consider to be the best editor for PowerShell.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now