Jun 17, 2013

How to modify Windows file timestamps and other attributes

If anyone's searching for a tool that allows you to modify a file's timestamps on Windows, like when it was created or last modified, don't go any further by risking to install some fishy "freeware" application or tool. You can use Windows Powershell for this just like you would use the touch command on Linux.

First get your item, pipe it to the get-member cmdlet and see if any time attributes are settable:

PS > Get-Item myfile.pdf | gm -Name *time

Your required time property should be {get;set;}-able if you're the owner of the file.

Then if for example you wanted to modify the LastWriteTime file attribute, store the item in a variable and then read that property and use the same format to set it. For instance:

PS > $myvar = Get-Item myfile.pdf
PS > $myvar.LastWriteTime

    Wednesday, December 12, 2012 12:18:15 PM

PS > $myvar.LastWriteTime = "Wednesday, December 10, 2012 12:12:12 PM"

Then check your attribute value again with:

PS > $myvar.LastWriteTime

And that's it. Hope I helped.