# * * * * * * * 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!"This code snippet for PowerShell script to extract version history of sharepoint list items.