-
Notifications
You must be signed in to change notification settings - Fork 2
/
GetItemVersionHistory
28 lines (23 loc) · 1.04 KB
/
GetItemVersionHistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#This script retrieves the version history of a specific item in a specified list. Field changes can be tracked by manually updating the script to include those fields
$ListName = "My List Name"
$siteUrl = "https://example.sharepoint.com/sites/demosite"
$ItemId = 1234
Connect-PnPOnline -Url $siteUrl
$list = get-pnplist -Identity $ListName
$item = Get-PnPListItem -List $list -Id $ItemId
$versions = = Get-PnPProperty -ClientObject $item -Property Versions
$VersionHistory = @()
Foreach($version in $versions)
{
$CreatedBy = Get-PnPProperty -ClientObject $version -Property createdby
$VersionHistory += New-Object PSObject -Property @{
'VersionId' = $version.VersionId
'Created by' = $CreatedBy.Title
'Created' = $version.Created
#Update here as required with your own columns
'My First Column' = $version.FieldValues["MyFirstColumn"]
'Another Column' = $version.FieldValues["AnotherColumn"]
'One More Column' = $version.FieldValues["OneMoreColumn"]
}
}
$VersionHistory | Export-Csv "VersionHistory $($ListName) $($ItemId).csv"