TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
PowerShell Script to Extract Version History of SharePoint List Items
Krishna Murthy
Jul 22
2015
Code
7.3
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
# * * * * * * * Variables Section * * * * * * * * * * * * * * * * * * $WebURL = "http://<<SharePointsite>>/sites/Opportunity/"
$ListName =
"Opportunity List"
$ReportFile =
"F:\Opportunity_VersionHistory.csv"
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #delete file
if
exists If(Test - Path $ReportFile) {
Remove - Item $ReportFile
}#Get the Web and List
$Web = Get - SPWeb $WebURL
$List = $web.Lists.TryGetList($ListName)#Check
if
list exists
if
($List - ne $
null
) {#Get all list items
$ItemsColl = $List.Items#Write Report Header
Add - Content - Path $ReportFile - Value
"Item ID, Version Lable, Created by, Created at, Title, Comments"
#Loop through each List item
foreach
($item
in
$ItemsColl) {#Iterate each version
foreach
($version
in
$item.Versions) {#Get the version content
$VersionData =
"$($item.id), $($version.VersionLabel), $($version.CreatedBy.User.DisplayName), $($version.Created), $($version['Title']), $($version['Comments'])"
#Write to report
Add - Content - Path $ReportFile - Value $VersionData
}
}
}
Write - Host
"Version history has been exported successfully!"
PowerShell
SharePoint List
Version History