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.

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

Hat tip to Steve’s article on

Written on December 6, 2013