Solved

Renaming multiple file extensions using Powershell

Posted on 2016-11-29
4
63 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Mal Osborne
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 84

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

733 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