Skip to content

Instantly share code, notes, and snippets.

@Rafisto
Created November 27, 2023 18:57
Show Gist options
  • Save Rafisto/e5830804ded17e924c1b29d5255dbf30 to your computer and use it in GitHub Desktop.
Save Rafisto/e5830804ded17e924c1b29d5255dbf30 to your computer and use it in GitHub Desktop.
Single modify creation and last write time of a file via PS

Commands to modify a single file

(Get-Item "<file_path>").CreationTime=("3 August 2019 17:00:00")
(Get-Item "<file_path>").LastWriteTime=("3 August 2019 17:00:00")
(Get-Item "<file_path>").LastAccessTime=("3 August 2019 17:00:00")

exercise: now do it for every file in a directory and subdirectories. Tip. use recursion.

These PowerShell commands are used to modify the file timestamps (creation time, last write time, and last access time) of a specified file. Let's break down each line:

  1. (Get-Item "<file_path>").CreationTime=("3 August 2019 17:00:00"):

    • Get-Item "<file_path>": This part retrieves information about the specified file (specified by <file_path>).
    • .CreationTime=("3 August 2019 17:00:00"): This part sets the creation time of the file to the specified date and time, in this case, "3 August 2019 17:00:00".
  2. (Get-Item "<file_path>").LastWriteTime=("3 August 2019 17:00:00"):

    • Similar to the first line, this command sets the last write time of the file to "3 August 2019 17:00:00".
  3. (Get-Item "<file_path>").LastAccessTime=("3 August 2019 17:00:00"):

    • This command sets the last access time of the file to "3 August 2019 17:00:00".

In summary, these commands are adjusting the creation time, last write time, and last access time of a specified file to the same specified date and time, which is "3 August 2019 17:00:00".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment