Rename Files with PowerShell

If you’re used to renaming files at the command prompt you might be surprised to discover that to rename files with PowerShell requires a few more keystrokes.

To rename files with PowerShell we need to use a scriptblock to construct the new filename:

This will change each file with the extension bak to the extension backup.

And if you’re a regular expressions junkie then -replace supports regular expressions inside the scriptblock too! You can have any valid PowerShell code inside the scriptblock as long as the output is a string for the new filename.

2 thoughts on “Rename Files with PowerShell

Have something to add? Let me know ...