Thursday, December 15, 2016

O365 Powershell script to get List Item Properties with Versions

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$web = Get-SPWeb -identity "Site URL"
$list = $web.Lists["ListName"]

$ListItemCollection = @()

foreach ($item in $list.Items) {
foreach($version in $item.Versions){
$data = @{
                        "Version" = $version.VersionLabel
                        "List Name" = $list.Title
                        "Created By" = $item["Author"]
                        "Created Date" = $item["Created"]
                        "Modified By" = $item["Editor"]
                        "Modified Date" = $item["Modified"]
                        "Item Name" = $item.File.Name                      
}
$ExportItem = New-Object PSObject -Property $data | Select "List Name", "Item Name", "Version", "Created By", "Created Date", "Modified By", "Modified Date"

$ListItemCollection += $ExportItem

}
}

$ListItemCollection | Export-CSV D:\List.csv -NoTypeInformation 

No comments:

Post a Comment