SharePoint Online: How to Update Document Properties using PowerShell?

Requirement: Update the Metadata of a File in SharePoint Online using PowerShell.

Update Document Metadata <a href=in SharePoint Online using PowerShell" width="851" height="315" />

How to bulk edit metadata in SharePoint Online?

One of the key features of SharePoint Online is the ability to store metadata, or properties, for each document in a library. These properties provide valuable information about the document, such as its status, author, and date of creation. In this article, we will cover how to update document properties in SharePoint Online using PowerShell. This can be useful for updating numerous documents with the same property values, or for automating updates to document properties as part of a workflow or process.

If you want to change the properties of multiple documents in a SharePoint Online document library at once, you can use the details pane in Modern Experience to bulk edit file metadata.

Follow these steps to bulk update document properties:

bulk edit metadata sharepoint online

  1. Browse your SharePoint Online document library >> Select the documents from the document library.
  2. Click on the little “i” button to open the details pane.
  3. Now, You can change the properties of the selected documents in bulk.
  4. Click Save to apply the changes.

Bulk edit metadata in SharePoint Online: Use “Quick Edit” to edit and update metadata for multiple files at one stretch in a Excel like Datasheet view!

SharePoint Online: PowerShell to Update Metadata of a File

Let me show you the PowerShell to update a file’s metadata in SharePoint Online. This can be helpful if you need to make updates to a large number of files at once or if you want to automate the process.

#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 $SiteURL= "https://crescent.sharepoint.com/sites/Marketing" $FileRelativeURL="/sites/Marketing/Shared Documents/Release Notes.dotx" #Setup Credentials to connect $Cred = Get-Credential Try < #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password) #Get the File $File = $Ctx.Web.GetFileByServerRelativeUrl($FileRelativeURL) $Ctx.Load($File) $Ctx.ExecuteQuery() #Set metadata of the File $ListItem = $File.ListItemAllFields $ListItem["ReviewTimestamp"] = [System.DateTime]::Now $ListItem.Update() $Ctx.ExecuteQuery() write-host -f Green "Document Metadata Updated Successfully!" >Catch

PowerShell to Set Metadata Value for All Files in a SharePoint Online Document Library

How about updating properties for all files in a document library using PowerShell?

#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 $SiteURL= "https://crescent.sharepoint.com/sites/Marketing" $ListName="Documents" #Setup Credentials to connect $Cred = Get-Credential Try < #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password) #Get All Items from the List $List = $Ctx.web.Lists.GetByTitle($ListName) $ListItems = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()) $Ctx.Load($ListItems) $Ctx.ExecuteQuery() #Loop through each item ForEach($ListItem in $ListItems) < #Set metadata of the List Item $ListItem["ReviewTimestamp"] = [System.DateTime]::Now $ListItem.Update() write-host -f Green "Document Metadata Updated Successfully for:" $ListItem["FileLeafRef"] >$Ctx.ExecuteQuery() > Catch

PnP PowerShell to Set Metadata of a File

Updating document properties in SharePoint Online using PowerShell can be accomplished using the PnP PowerShell module. Here is how you can upload a file to the SharePoint Online document library and set its metadata using PnP PowerShell:

#Variables $SiteURL = "https://crescent.sharepoint.com/sites/branding" $FilesPath = "C:\Temp\Technical Design.docx" $SiteRelativePath = "/documents" #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -Interactive #Get the File from the local path $File = Get-ChildItem -Path $FilesPath #Get Created on, Last Modified Properties of the file $Created = [DateTime]$File.CreationTime $Modified = [DateTime]$File.LastWriteTime #Upload the file to SharePoint Online folder - and Set Metadata Add-PnPFile -Path $File.FullName -Folder $SiteRelativePath -Values @

Similarly, to set the metadata of an existing file, use:

#Parameters $SiteURL = "https://crescent.sharepoint.com/sites/Marketing" $ListName = "Branding" $SiteRelativeURL = "/Branding/Technical Design.docx" $CreatedBy= "Salaudeen@crescent.com" $Title = "New Design Document V2.docx" #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -Interactive #Get the File from SharePoint $File = Get-PnPFile -Url $SiteRelativeURL -AsListItem #Update document properties Set-PnPListItem -List $ListName -Identity $File.Id -Values @

Wrapping Up

In conclusion, updating document properties in SharePoint Online using PowerShell can be a powerful and efficient way to manage content in the platform. By using the CSOM PowerShell script or PnP PowerShell cmdlets, you can automate updates to document properties as part of a workflow or process, or update a large number of documents with the same property values.

If you want to bulk edit document properties from a CSV file, refer: SharePoint Online: Bulk Update Metadata from a CSV File using PowerShell