当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 比较 SharePoint 列表项目版本历史记录

作者:精品下载站 日期:2024-12-14 21:08:15 浏览:15 分类:玩电脑

使用 PowerShell 比较 SharePoint 列表项目版本历史记录


要求:比较 SharePoint 列表项的版本历史数据并根据特定字段的值更改更新元数据列。

一些背景知识:我们有一个带有“状态”列的项目跟踪列表。我们想要深入了解特定项目的状态何时设置为“已拒绝”。

PowerShell 比较版本历史数据并更新列值:

作为上述要求的解决方案,让我们比较列表项版本以捕获特定项的“状态”列何时更改为“已拒绝”,并获取特定版本的创建日期以更新列表的“拒绝日期”列物品。让我们使用 PowerShell 比较 SharePoint 中的版本历史记录:


Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Parameters
$SiteURL="https://intranet.crescent.com"
$ListName = "Projects"

#Get web and List 
$Web = Get-SPWeb $SiteURL
$List = $web.Lists.TryGetList($ListName)

#Get all list items
$ListItems = $List.Items

#Iterate through each list item
Foreach($Item in $ListItems)
{
    #Iterate through each version
    ForEach($Version in $Item.Versions) 
    {
        #Check if the status column is "Rejected"
        If($($version['Status']) -eq "Rejected")
        {
            #Update Rejected Date value of the item from version
            $Item["RejectedDate"] = $($version.Created)
            $Item.SystemUpdate()
            Write-host "ID:$($item.id), Version:$($version.VersionLabel), CreatedBy:-$($version.CreatedBy.User.DisplayName), Status:-$($version['Status'])"
            Break
        }
    }
}

该脚本比较每个列表项版本并更新“RejectedDate”列值。如果要导出列表项版本历史记录,请使用:如何使用 PowerShell 导出 SharePoint 列表项版本历史记录?

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯