0

Please find my below code and provide some suggestions. As I am able to export "id, Title, VersionLabel, DisplayName, Created,Check-In Comment" but I wants change fields also marked Red in the image.

enter image description here

$WebURL="SiteURL"
$ListName ="ListName"
$ReportFile = "C:\Sachin\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,Item Title, Version ID, Modified By, Modified at,Comments"

#Loop through each item
foreach ($item in $ItemsColl)
{
#Iterate each version
foreach($version in $item.Versions)
{

$version.Fields
#Get the version content
$VersionData = "$($item.id),$($version['Title']), $($version.VersionLabel), $($version.CreatedBy.User.DisplayName),$($version.Created),$($version['Check In Comment'])"
#Write to report
Add-Content -Path $ReportFile -Value $VersionData
}
}
}
Write-Host "Version history has been exported successfully!"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.