SharePoint 2010 & Powershell: GetFile returns different date time than the web server

Scenario

When we trying to retrieve item from PowerShell, when we tried to see the created and modified time of the item, it look different to what shown in the list item view in the SharePoint UI?

Why?

Why is it returning different time?

Because?

In PowerShell, when you try to get the file like the following:

$web = Get-SPWeb “http://…”

$file = $web.GetFile(“http://…/file.docx”)  or foreach($file in $web.GetFolder(“folder name”).files) …

When we try to access the file “TimeLastModified” or “TimeCreated” property, it will return you a date time that is different than what you see in the list item UI?

Because it is returning the time adjusted in summer time format.

Solution

By using ToLocalTime() solves the problem, it will return time with adjusted time to our server time, like the following:

$file.TimeLastModified.ToLocalTime() and $file.TimeCreated.ToLocalTime()

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s