How to report SharePoint list item versions in Office 365/SharePoint online?
Hello SharePointers, Below are Powershell script to get all the version history of all list items in SharePoint online/Office 365.
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.ExecuteQuery()
$Query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
$ListItems = $List.GetItems($Query)
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
$VersionHistory = @()
Foreach ($Item in $ListItems)
{
write-host "Processing Item:" $item.id -f Yellow
#Get all versions of the list item
$Versions = $Item.versions
$ctx.Load($Versions)
$Ctx.ExecuteQuery()
If($Versions.count -gt 0)
{
#Iterate each version
Foreach($Version in $Versions)
{
#Get the Creator object of the version
$CreatedBy = $Version.createdby
$Ctx.Load($CreatedBy)
$Ctx.ExecuteQuery()
#Send Data to object array
$VersionHistoryData += New-Object PSObject -Property @{
'Item ID' = $Item.ID
'Issue/Rejection Description' = $Version.FieldValues["Issue_x002f_Rejection_x0020_Desc"]
'Resolution Feed'=$Version.FieldValues["Mastering_x0020_Digital_x0020_Co"]
}
}
}
Happy SharePointing 🙂