Joseph Jojo John
Joseph Jojo John

Reputation: 551

update SharePoint online document library column property using pnp PowerShell

I need to recursively update properties of folders in SharePoint online document library based on some condition using pnp PowerShell cmdlets. I could see the cmdlets to update column properties of lists, but not for document library.

using the below command I fetched all the folders in the library. How I can update some custom properties?

$folders = Get-PnPFolderItem -FolderSiteRelativeUrl $ParentFolder -ItemType Folder -Recursive

Appreciate your help.

Upvotes: 1

Views: 2115

Answers (1)

Joseph Jojo John
Joseph Jojo John

Reputation: 551

Actually I have found answer for this. the PnPFolderItems command can't handle meta data. I could able to change the property values using PnPListItem command. Check the code below.

Connect-PnPOnline -Url $SiteURL -Credentials $Cred

$clientContext = Get-PnPContext
$targetWeb = Get-PnPWeb
$targetList = $targetWeb.Lists.GetByTitle("Documents") # Library Internal Name
$clientContext.Load($targetList)
$clientContext.ExecuteQuery()

$fields = "FileLeafRef","Project" # fields that you need to access and update
$ListItems = Get-PnPListItem -List $targetList -Fields $fields
foreach($ListItem in $ListItems){
    if($ListItem.FileSystemObjectType -eq "Folder"){ # filter folders
        $ListItem["Project"] = "new value to the custom column"
        $ListItem.Update()
    }
}

This code worked for me. If any better code/cmdlets available for the same, please mention here.

Thank you

Upvotes: 1

Related Questions