Rename a File in SharePoint Document Library using PowerShell
Requirement: Rename a File in the SharePoint document library using PowerShell.
How to rename a file in SharePoint?
One of the most basic tasks that users of SharePoint document libraries perform is renaming files. Renaming a file in SharePoint is a simple process that can be done in a few easy steps. SharePoint provides a user-friendly interface that allows users to rename files.
Here are the step-by-step instructions for renaming a file in SharePoint 2016:
- Navigate to the document library that contains the file you want to rename.
- Right-click on the file >> Select “Rename” from the drop-down menu.
- Enter the new name for the file in the “Name” field in the dialog box that appears.
- If you wish, you can also add a description for the file in the “Description” field.
- Click on the “OK” button to save the changes.
- The file will be renamed with the new name that you have provided and the new name will appear in the document library.
That’s it! You have successfully renamed a file in SharePoint!
PowerShell to Rename a File in SharePoint:
Renaming a file in SharePoint can be tedious if there are many files to be renamed. Luckily, We have PowerShell to automate the process of renaming files in a SharePoint Document Library. In this blog post, we’ll look at how to use PowerShell to rename files in SharePoint.
Renaming files is one way to keep your documents organized and easy to find. Let’s rename a file with ID “4” in the “Documents” SharePoint library.
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
#Variables for processing
$WebURL = "https://intranet.crescent.com"
$ListName = "Documents"
$ItemID ="4"
$NewFileName="sharepoint databases.pptx"
#Get Web, List and Item
$Web = Get-SPWeb $WebURL
$List = $Web.Lists[$ListName]
$ListItem = $List.GetItemByID($ItemID)
#Check-out and Rename the file
$ListItem.File.CheckOut()
$ListItem["Name"] = $NewFileName
$ListItem.Update()
$ListItem.File.CheckIn("File has been renamed!")
Instead of Item ID, let’s use the existing file name and rename it.
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
#Variables for processing
$WebURL = "https://intranet.crescent.com"
$ListName = "Documents"
$FileName="sharepoint databases.pptx"
$NewFileName="sharepoint databases v2.pptx"
#Get Web, List and Item
$Web = Get-SPWeb $WebURL
$List = $Web.Lists[$ListName]
$ListItem = $List.Items | Where {$_["Name"] -eq $FileName}
If($ListItem -ne $NULL)
{
#Check-out and Rename the file
$ListItem.File.CheckOut()
$ListItem["Name"] = $NewFileName
#change the Title of the file name
$ListItem["Title"] = $NewFileName
$ListItem.Update()
$ListItem.File.CheckIn("File has been renamed!")
Write-Host "File has been Renamed!" -f Green
}
else
{
Write-Host "File Not Found!" -f Yellow
}
It can be tedious to rename files in SharePoint Document Library if there are several files to be renamed. With PowerShell, you can automate this process in a powerful and efficient manner. In this article, we have discussed how to rename a file in the SharePoint Document Library using PowerShell. You can easily rename files in SharePoint Document Library using PowerShell by following the steps outlined in this article.
Here is the post for SharePoint Online: SharePoint Online: Rename Files in Document Library using PowerShell