The following tutorial demonstrates how you can edit file timestamps — create, last access and last write — using Windows PowerShell.

PowerShell is part of any modern version of Microsoft’s Windows operating system. Microsoft shifted to PowerShell away from the Command Prompt on Windows 10, but did not remove the command prompt doing so.

Windows 10 users and administrators have access to both, but the development focus lies clearly on PowerShell.

Each file on Windows, and other operating systems as well, has several timestamps associated with it. The file system keeps track of the files creation time, last access time, and last write time.

How to edit timestamps with Windows PowerShell

 

First thing you need to do is to launch a PowerShell window.  Tap on the Windows-key, type PowerShell and hit the Enter-key afterwards. Note that this launches the prompt under the current user account. If you require an elevated prompt, for instance to edit file timestamps of folders that the user has limited access to, hold down Shift-key and Ctrl-key additionally.

The three commands that you require are the following ones:

  • $(Get-Item FILENAME.EXT).creationtime=$(DATE)
  • $(Get-Item FILENAME.EXT).lastaccesstime=$(DATE)
  • $(Get-Item FILENAME.EXT).lastwritetime=$(DATE)

The three commands change the creation, last access and last write timestamps of the file when you run them.

Note: Last Access Time is not enabled by default on all supported versions of Windows because of performance concerns.

To give you some examples:

  • $(Get-Item test.txt).creationtime=$(Get-Date)
  • $(Get-Item test.txt).lastaccesstime=$(Get-Date “12/24/2011 07:15 am”)
  • $(Get-Item LastRunDateFile.info).lastwritetime=$(Get-Date “04/01/2020”)

The first command sets the creation timestamp of the file text.txt to the current date and time. The second command changes the last access time and date to December 24th, 2011 at 7:15 am.

Note that the command requires that the file is in the current directory of the PowerShell prompt.

Helpful commands

Once thing that may be useful is to list the file timestamps of the current folder before and after you run the PowerShell command. This makes it easier to find files that still require changing, and check whether the changes have been applied correctly.

 

Get-ChildItem -force | Select-Object Mode, Name, CreationTime, LastAccessTime, LastWriteTime | ft

The command lists all files and folders of the current path, and displays the creation time, last access time and last write time of each item in a table.

  • -force in this context includes hidden and system files in the output.
  • ft is short for format table.

If you just need the create timestamp, run Get-ChildItem -force instead.

The following script runs the operation on all files.

$modifyfiles = Get-ChildItem -force | Where-Object {! $_.PSIsContainer}
foreach($object in $modifyfiles)
{
$object.CreationTime=(“11/11/2011 12:00:00”)

$object.LastAccessTime=(“11/11/2011 12:00:00”)

$object.LastWritetime=(“11/11/2011 12:00:00”)

}

Just copy and paste it, and change it according to your requirements.

Share This Via: