title: Display Correct Modified By and Modified times and dates
body: <p>I have a script that outputs to CSV all items from all Lists and all files from all Libraries below:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Below is a sample output of the script:
  <a href="https://i.stack.imgur.com/hu5dF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hu5dF.png" alt="enter image description here"></a></p>
  
  <p>Displayed above is a file (Lions.pdf) with 3 versions total. Version 3 is the current version of the file and the data for <code>Modified By</code> and <code>Modified Date</code> displays correct as Doe, John.</p>
  
  <p>When I go to Version History I see a problem:</p>
  
  <ul>
  <li>For Version 2 of the file it was modified by Parayno, Frank with a modified date of 10/25/11 5:15 PM</li>
  <li>For Version 1 of the file it was modified by Doe, John with a modified date of 6/28/11 11:23 AM.</li>
  </ul>
  
  <p>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 <code>Modified By</code> and <code>Modified Date</code>?</p>
  
  <p>Below is the desired output of the script:</p>
  
  <p><a href="https://i.stack.imgur.com/4ZHqF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4ZHqF.png" alt="enter image description here"></a></p>