kwizcom banner advertisement

SharePoint Online: Update Metadata of a Document using PowerShell

Requirement: PowerShell to update metadata of a file in SharePoint Online.

PowerShell to Update the Metadata of a File in SharePoint Online:
How to set metadata of a document in SharePoint Online? Lets update the "Status" Column value of a particular file in a SharePoint Online Document library.
#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://crescent.sharepoint.com/sites/Ops"
$FileRelativeUrl="/sites/Ops/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["Status"] = "Completed"
        $ListItem.Update()
        $Ctx.ExecuteQuery()

        Write-host -f Green "File's Metadata has been Updated Successfully!"
     }
    Catch {
        write-host -f Red "Error Updating Metadata of the File!" $_.Exception.Message
   }
and the result:
powershell to update metadata of a file in sharepoint online
This PowerShell script sets metadata column value of the given document.
SharePoint Online: Update Metadata of a Document using PowerShell SharePoint Online: Update Metadata of a Document using PowerShell Reviewed by Salaudeen Rajack on August 30, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.