Go to ...

RSS Feed

March 29, 2020

PowerShell – Change file and folder timestamps

All files and folders in Windows have three different timestamps: Date Created, Date Accessed, and Date Modified. Timestamps are stored in variables named CreationTime, LastAccessTime and LastWriteTime. As variables, they can be edited and changed.

I copied a few files and folders to a folder named Demo to show how to do this. Let’s first check the folder contents using the PowerShell cmdlet Get-ChildItem (#1 in screenshot):

Click screenshots to open them enlarged in a new tab.

Run without any parameters, Get-ChildItem by default shows Mode (attributes), name, and Date Modified (LastWriteTime) for each file and folder. For files, also the size is shown.  To get more information, we need to first select the information we want to show, then pipe the cmdlet output to a table using the following command (shown as #2 in the preceding screenshot):

Get-ChildItem | Select-Object Mode, Name, CreationTime, LastWriteTime, LastAccessTime | Format-Table

You will notice that as I copied these files and folders today to my Demo folder, their Date Created and Date Accessed timestamps are all the same. Thus, only the Date Modified column shows real timestamps.

OK, let’s say that I for any reason need to change the Date Created timestamp of Oobe.xml to 11th of January, 2019, at 23:33 (11:23 PM). For that, I use the Get-Item cmdlet:

(Get-Item "Oobe.xml").CreationTime=("11-Jan-2019 23:33:00")

For date and time values, I use the short date and long time formats as set in my system:

Checking the timestamps again, we can see that Date Created timestamp for that file was changed:

By default, you can only change Date Created (CreationTime) and Date Modified (LastWriteTime) timestamps. Date Accessed (LastAccesTime), when the file or folder was opened last time, is not updated by default, and it cannot be changed. To enable Date Accessed, enter the following command in an elevated PowerShell or Command Prompt:

fsutil behavior set disablelastaccess 0

Value 0 enables LastAccessTime and allows its timestamp being changed, value 1 disables it (restores defaults).

That’s it. You’ll never know, you might someday need to change the timestamps. Fortunately, it is both easy and fast.


Author: Kari Finn

A former Windows Insider MVP, Kari started in computing in the mid 80’s writing code for VAX / VMS systems. Since then, he’s worked in a variety of IT positions. He specializes in Windows image capture, customization, repair and deployment as well as Hyper-V virtualization. Kari is a proud Team Member at number #1 Windows site TenForums.com.

Leave a Reply

More Stories From Admin Tools