[英]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.我需要使用 pnp PowerShell cmdlet 根据某些条件递归更新 SharePoint 在线文档库中文件夹的属性。 I could see the cmdlets to update column properties of lists, but not for document library.
我可以看到 cmdlet 来更新列表的列属性,但不能用于文档库。
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.感谢你的帮助。
Actually I have found answer for this.其实我已经找到了答案。 the PnPFolderItems command can't handle meta data.
PnPFolderItems 命令无法处理元数据。 I could able to change the property values using PnPListItem command.
我可以使用 PnPListItem 命令更改属性值。 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.
如果有任何更好的代码/cmdlet 可用,请在此处提及。
Thank you谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.