Handy DB Scripts – Rename w/Powershell

Powershell has become a nice toolbox addition to a must-have for, say, Azure. Here’s a slick way to rename files either one or in bulk.

Lee

Open Powershell #1: Windows Powershell ISE

imagel

Open Powershell #2: command prompt

image

Command:

Get-ChildItem -Filter “*string to replace*” -Recurse | Rename-Item -NewName {$_.name -replace ‘string to replace’,’new str’ }

***use the –whatif switch optionally to check what the script will do before actually executing

Get-ChildItem -Filter “*string to replace*” -Recurse | Rename-Item -NewName {$_.name -replace ‘string to replace’,’new str’ } -whatif

image

Replace above values in “” with the following:

string to replace– is the string in the filename that you want to replace

new str  – what you want instead of ‘old string’ value. If nothing, put “”

Demo: Here, I’m replacing Copy with File.

This command by the way is not case sensitive, so keep that in mind.
Happy Renaming!

Renamegif

 

 

Credit –>  https://blogs.technet.microsoft.com/heyscriptingguy/2013/11/22/use-powershell-to-rename-files-in-bulk/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s