In this post, we’ll provide a straightforward PowerShell script that will enable you to replace a certain word in a SharePoint File Name using PowerShell.
Consider that you need to replace a specific term in the file name of each file since there are numerous files in a document library that have been uploaded with the incorrect name. As a result, in this scenario, if you need to manually do this process for each file using a browser, you will need to take at least three steps for each file as follows:
- Check out the file
- Edit file properties.
- Save and check in the file.
Actually, performing these processes for a small number of files is tedious and will waste your time, but when you consider that you will need to do it for roughly 1000 files, just think how much time you will take to do it!!
Therefore, we have provided this simple PowerShell Script “Replace File Name” that do the following:
- Check if the SharePoint site exists or not.
- Check if the provided document library already exists or not.
- Get the total number of files.
- Loop for each file in your document library and check if the file name contains the specified word that you need to replace.
- After that, it checks if the file is checked out or not to start the replacement process.
- Print the total number of updated files.
Download the Replace SharePoint File Name using PowerSell from GitHub.
How to use Replace File Name PowerShell Script?
- Download the PowerShell Script file from My GitHub.
- In your SharePoint Server, Open Windows PowerShell ISE as Administrator.
- From the file menu, open the downloaded file.
- Provide the following values based on your needs.
- $siteURL (the site URL that holds the document library)
- $DocLibName (the name of the document library that holds your files)
- $oldword (the word that you need to replace)
- $newword (the word that will be replaced)
- Once you provided the required values, click on F5 to run your script.
Replace File Name PowerShell Script Output
Below are the possible result when you run the Update Page Properties PowerShell Script
Incorrect Site URL
Document Library is not found
Best case Result
If you have numerous files and you need to update their names based on a specific term, you will require a lot of time to achieve this. In such scenarios, the Replace File Name PowerShell Script would help you to easily and quickly do a bulk update of the name for all files based on a specific word.
Follow the SharePoint Administration repo on GitHub to get all new PowerShell scripts that help you to manage SharePoint Server, and download the “Replace File Name” PowerShell script to can replace a specific word in a SharePoint File Name using PowerShell.
- SharePoint 2019.
- SharePoint 2016.
- SharePoint 2013.