PowerShell – Mass Rename Files / Directories

|

Recently I needed to rename files and directories in a repository so I came up with the PowerShell script.

NOTE: Use caution using this.

cd "C:\Users\dkittell\Repos\TestRepo"
Get-ChildItem -File -Recurse | Rename-Item –NewName { $_.name –replace " ","_" } # Replace space with underscore - Files
Get-ChildItem -File -Recurse | Rename-Item –NewName { $_.name –replace "'","" } # Remove single quote - Files
Get-ChildItem -Directory -Recurse | Rename-Item –NewName { $_.name –replace " ","_" } # Replace space with underscore - Directories
Get-ChildItem -Directory -Recurse | Rename-Item –NewName { $_.name –replace "'","" } # Remove single quote - Directories
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.