title: How to Display Modified Time and Modified By Fields Correctly with Powershell
body: <p>I have a script that outputs to CSV all items/files from all Lists and Libraries. In addition, it displays the current and previous versions of an item/file. This also displays which user modified the file for each version and also displays the date/time the file was modified for every version:</p>
  
  <pre><code>function Get-DocInventory([string]$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" = $version["Editor"]
  "Modified Date" = ($version["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();
  }
  }
  
  
  
  
  Get-DocInventory  | Export-Csv -NoTypeInformation -Path C:\GenerateReport.csv
  </code></pre>
  
  <p>Below is a sample of what the script outputs:</p>
  
  <p><a href="https://i.stack.imgur.com/iGV8d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iGV8d.png" alt="enter image description here"></a></p>
  
  <p>And below is an excel example of what I see when I go to the Version History of the Lions.pdf file:</p>
  
  <p><a href="https://i.stack.imgur.com/SvrkZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SvrkZ.png" alt="enter image description here"></a></p>
  
  <p>I have 2 problems:</p>
  
  <ul>
  <li>The column Modified By is displaying email and domain username which is not required.</li>
  <li>My script displays the column Modified Date as 5 hours ahead. The script output for Version 1 of Lions.pdf displays time as 11:23 AM. But when I go to Version History of Lions.pdf it says that Version 1 was modified at 6:23 AM. The time discrepancy is the same across the board as 5 hours ahead which is incorrect.</li>
  </ul>
  
  <p>I can't seem to figure out what I am doing wrong here. Can someone please assist in the issue I am having? My main concern is the time and I would greatly appreciate any assistance.</p>