The date of a file can be set or manipulated arbitrarily with PowerShell. In the screenshot you can see a few example values that have been set arbitrarily. The procedure has been tested with Windows PowerShell 5.1.
With Get-Member you can display the time attributes of a file.
| |

The interesting attributes are:
- CreationTime (when the file was created)
- LastAccessTime (when the file was last accessed)
- LastWriteTime (when the file was last modified)
As you can see from the {get;set;} at the end, you can not only read these attributes, but also set them.
Examples
In the following examples I show how to change the modification date, the last access time, and the creation timestamp for individual files or all files in a folder.
Notes on the examples
Generate a date
I prefer to generate the date in the following format: 2020-09-13T13:37:37 (see also ISO 8601), or alternatively simplified as 2020-09-13 13:37. This standardized format works independently of OS localization.
Abbreviations and aliases
With gci (abbreviation/alias for Get-ChildItem) we read all items (folders and files) in the current folder.
With % (alias for ForEach-Object) we iterate through all items.
Change the creation date
Examples for changing the creation date (“Created”):
| |
Change the modification date
Examples for changing the modification date (“Modified”):
| |
Change the last access date
Examples for changing the access timestamp (“Last Access”):
| |
Conclusion
Because the time attributes of files can be manipulated arbitrarily, they should not be trusted. They can at best be used as a clue for an action in a system. But they are definitely not proof.
