Hi @Tom Molskow ,
Do you mean that you are going to rename a document using PowerShell, right? If yes, please take a reference to below PowerShell scripts.
PowerShell CSOM Script to rename a document in SharePoint Online:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Set Variables for Site URL, Old File Name and New File Name
$SiteURL= "https://contoso.sharepoint.com/sites/sales/"
$OldFileURL="/sites/Sales/Documents/Legal.docx"
$NewFileURL="/sites/Sales/Documents/LegalTemplate.docx"
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
#Rename the File
$File = $Ctx.Web.GetFileByServerRelativeUrl($OldFileURL)
$File.MoveTo($NewFileURL, [Microsoft.SharePoint.Client.MoveOperations]::Overwrite)
$Ctx.ExecuteQuery()
write-host -f Green "File Renamed successfully!"
}
Catch {
write-host -f Red "Error Renaming File!" $_.Exception.Message
}
Rename a document using PnP PowerShell:
#Config Variables
$SiteURL = "https://contoso.sharepoint.com/sites/marketing"
$FileURL= "Shared Documents/Active/Office 365 Proposal.pdf"
$NewFileName ="Office 365 Proposal V2.pdf"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Rename the File
Rename-PnPFile -SiteRelativeUrl $FileURL -TargetFileName $NewFileName -Force
==========
Updated
==========
To modify the "Title" field of a document:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Set parameter values
$SiteURL="https://contoso.sharepoint.com/sites/teamsite"
$FileRelativeUrl="/sites/teamsite/Shared Documents/Investment Process.pptx"
Try {
#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
$File = $Ctx.web.GetFileByServerRelativeUrl($FileRelativeUrl)
$Ctx.Load($File)
$Ctx.ExecuteQuery()
#Set Metadata of the File
$ListItem = $File.ListItemAllFields
$Listitem["Title"] = "NewTitleTest"
$ListItem.Update()
$Ctx.ExecuteQuery()
Write-host -f Green "File's title has been Updated Successfully!"
}
Catch {
write-host -f Red "Error Updating title of the File!" $_.Exception.Message
}
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.