Append to multiple filenames in Sharepoint online library

Welcome Forums General PowerShell Q&A Append to multiple filenames in Sharepoint online library

Viewing 3 reply threads
  • Author
    Posts
    • #281852
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

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

      filenameD32.pdf
      filenameC45.pdf
      filename435.pdf

      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.

      Thanks

    • #281888
      Participant
      Topics: 17
      Replies: 1951
      Points: 3,987
      Helping Hand
      Rank: Community Hero

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

      SharePoint 2016: Rename File in Document Library Using PowerShell

      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.

    • #282029
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      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.

      Thanks
      John

    • #284200
      Participant
      Topics: 11
      Replies: 132
      Points: 896
      Helping Hand
      Rank: Major Contributor

      @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:

      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.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.