Batch Rename Files To Remove Substring From File Name Using PowerShell

Written on December 6, 2013

Use this PowerShell command to rename all the files in the directory to remove the “StoredProcedure” substring. This substring showed up for me when SQL Server Management Studio’s Generate Scripts utility wrote the files out to disk. The same suffix is present when scripting out other objects - View, Table, etc.

Remove Filename Substrings With PowerShell

Open a command prompt, navigate to the directory your files are in, and run this one-liner to remove those substrings.

PowerShell
Dir *.StoredProcedure.sql | rename-item -newname { $_.name  -replace ".StoredProcedure","" }

Hat tip to Steve’s article on Tweaks.com

Written on December 6, 2013