SharePoint 2019: Replace File Name using PowerShell

How to replace SharePoint file name using PowerShell

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.

Replace File Name using PowerShell
Replace SharePoint file name using Powershell

Replace File Name in SharePoint 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:

  1. Check out the file
  2. Edit file properties.
  3. 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:

  1. Check if the SharePoint site exists or not.
  2. Check if the provided document library already exists or not.
  3. Get the total number of files.
  4. Loop for each file in your document library and check if the file name contains the specified word that you need to replace.
  5. After that, it checks if the file is checked out or not to start the replacement process.
  6. Print the total number of updated files.
replace file name using Powershell in SharePoint 2019

Download the Replace SharePoint File Name using PowerSell from GitHub.

How to use Replace File Name PowerShell Script?

  1. Download the PowerShell Script file from My GitHub.
  2. In your SharePoint Server, Open Windows PowerShell ISE as Administrator.
  3. From the file menu, open the downloaded file.
  4. 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)
replace a specific word in SharePoint file name using Powershell
  1. 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

sharepoint site is not found powershell

Document Library is not found

sharepoint document library is not found powershell

Best case Result

SharePoint file name replacement using PowerShell - output


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.

Applies To
  • SharePoint 2019.
  • SharePoint 2016.
  • SharePoint 2013.
See Also

Leave a Reply

Scroll to Top