How would I use powershell to rename a pdf file in a document library? I've seen examples online that move files or rename while moving but not an example where the files are renamed in place (ie to keep them in the same document library)

  • Title or actual file Name?
    – Benny Skogberg
    Commented Sep 11, 2016 at 8:14

1 Answer 1

  • Open SharePoint Management Shell as Administrator.

  • Copy this code , Edit it with your entries ($Web,$DocLib,$filename) , Paste it in SharePoint Management Shell

$Web = Get-SPWeb "http://epm/workflow"
$DocLib = $Web.Lists["Doc"]          
$filename = "Qassas.pdf"
 foreach($ListItem in $DocLib.Items)
     if($ListItem["Name"] -eq $filename) 

             $ListItem["Name"] = "Your New Name"
             $ListItem["Title"] = "Your New Title"
             $ListItem.File.CheckIn("File Name Updated")


enter image description here

For more details Check Change File Name in SharePoint Document Library Via PowerShell

  • Thanks M.Qassas. The extra file checkout functionality makes sense. I have some examples that use web.dispose at the end. Is that necessary?
    – Dkong
    Commented Sep 13, 2016 at 4:02
  • 1
    Dear @Dkong , once you close the PowerShell, the memory is freed so don't worry if you do not use dispose. especially in a simple script, but if you use a big script that loop to web and lists and you are working in production , make sure to dispose of SPWEB , SPSITE. please don't hesitate to tell me if you need more clarification . Commented Sep 13, 2016 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.