0

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:

enter image description here

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:

enter image description here

  • curious to know where u run this command from? is it the PowerShell within the SharePoint server ?! I am running on my PC and I get message Get-SPWeb is not recognised – Bucki Jan 26 '18 at 11:40
3

I'm guessing it is because of this section:

 "Modified By" = $item["Editor"]
 "Modified Date" = ($item["Modified"] -as [datetime]).DateTime

In reality, you should be using $version to get to the version history of the item. You are iterating over each version of the item, yet you are referencing the item properties. Something like:

"Modified By" = $version["Editor"]
 "Modified Date" = ($version["Modified"] -as [datetime]).DateTime
  • I have tried what you suggested and it sort of works. The output with the suggested changes is displayed here: plus.google.com/101260755580272499158/posts/…. Essentially the Modified By looks like it is displaying the user's email and such. As far as the Modified Date it is displaying the time 5hrs ahead. Could you please assist? Also not sure how to add an image to comments hence the link. Apologies. – Aspire27 Nov 2 '15 at 21:05
1

It looks like you're using $item["Modified"] to get the modified date of the version - I think you need to use $version["Modified"] or else it will just continue to use the modified date of the current, latest version. Same for the rest of the fields.

Hope this helps!

  • I have tried what you suggested and it sort of works. The output with the suggested changes is displayed here: plus.google.com/101260755580272499158/posts/…. Essentially the Modified By looks like it is displaying the user's email and such. As far as the Modified Date it is displaying the time 5hrs ahead. Could you please assist? Also not sure how to add an image to comments hence the link. Apologies. – Aspire27 Nov 2 '15 at 21:12
0

Don't use the same time zone conversion for file created or file modified date. If you use, you will get -4 to -6hrs difference.

0

use the following code to get the version history modified date without any time difference.

$web.RegionalSettings.TimeZone.UTCToLocalTime($Version.Created) 

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.