Append to multiple filenames in Sharepoint online library

We have a SP online library which has thousands of PDF files. I have been tasked with appending " - SCS" to each filename so that


would become

filenameD32 - SCS.pdf
filenameC45 - SCS.pdf
filename435 - SCS.pdf

I am the proverbial jack of all trades IT administrator and know powershell to a degree, but would not consider myself a proficient scripter so am after some guidance on connecting to the SharePoint library and renaming these files please.


Have you done any research or tried anything? Here is a link for SP 2016:

Haven’t worked with SP in a while, but $ListItem[“Name”] represents the name, so you would just do a -replace .pdf with ’ - SCS.pdf’. Not sure what what properties are available in the list like file ext or basename. You’d filter if($ListItem[“Name”] -like ‘*.pdf’) or if there is an extension you could use that to filter.

Hi Rob,

Thanks for the reply. Have looked at lots of Google articles etc but most involved connecting SharePoint as a mapped drive or network location and doing it locally, but due to the volume of files the folder shows as empty. A couple of scripts I tried renamed the files but omitted the .pdf. I could download, rename & upload but would rather figure out a way to do it online as I am sure this wil pop up again. I will have a look at your link.


@John W:

If you haven’t found a solution, this should work… I use the SharePointPnPPowerShell module for pretty much any SharePoint Online stuff and it solves your problem very simply (assuming all files to be renamed are in the same directory, otherwise a little more work is needed).

Essentially, get all PDF files in the Document Library, and for each one, append the " - SCS" to the file name:

# Connect to SharePoint Online site
$siteUrl = ''
Connect-PnPOnline –Url $siteUrl –UseWebLogin

# specify the Document Library (and subfolder path if necessary)
$pdfLibrary = "/Shared Documents/pdf"

# get all .pdf files and append ' - SCS' to them
Get-PnPFolderItem -FolderSiteRelativeUrl $pdfLibrary -ItemType File |
    Where-Object -Property Name -Match '\.pdf$' |
    ForEach-Object -Process {
        $targetFileName = $_.Name -replace '\.pdf$', ' - SCS.pdf'

        Rename-PnPFile -ServerRelativeUrl $_.ServerRelativeUrl -TargetFileName $targetFileName -Force

        Write-Output ('Renamed "{0}" to "{1}"' -f $_.Name, $targetFileName)

The Rename-PnPFile cmdlet requires only the new file name be specified in the -TargetFileName parameter (do not include the entire location). The -Force is needed to suppress confirmation prompts for each file rename.