I have a script that outputs to CSV all items from all Lists and all files from all Libraries below:
function Get-DocInventory([string]$siteUrl) {
#$site = New-Object Microsoft.SharePoint.SPSite $siteUrl
$web = Get-SPWeb "http://contoso.com/sites/Depts3/HBG"
foreach ($list in $web.Lists) {
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"] -as [datetime]).DateTime
"Modified By" = $item["Editor"]
"Modified Date" = ($item["Modified"] -as [datetime]).DateTime
"Item Name" = $item.Name
}
New-Object PSObject -Property $data | Select "List Name", "Item Name", "Version", "Created By", "Created Date", "Modified By", "Modified Date"
}
}
$web.Dispose();
}
#$site.Dispose()
}
Get-DocInventory | Export-Csv -NoTypeInformation -Path C:\GenerateReport.csv
Below is a sample output of the script:
Displayed above is a file (Lions.pdf) with 3 versions total. Version 3 is the current version of the file and the data for Modified By and Modified Date displays correct as Doe, Jane.
When I go to Version History I see a problem:
- For Version 2 of the file it was Modified By Parayno, Frank with a Modified Date of 10/25/11 5:15 PM
- For Version 1 of the file it was Modified By Doe, John with a Modified Date of 6/28/11 11:23 AM.
The script seems to populate the previous versions with the most current user who modified the file, in this case, Doe, Jane. Also, for the column Modified Date, it is displaying the same date/time from Version 3 to Version 2 and 1. What can I do to the script to display the correct user and date/time for the columns Modified By and Modified Date? Can someone please assist?
Below is the desired output of the script: