From time to time, you may need to modify the time stamp of a file for archiving or any other reasons.
This PowerShell script comes in handy when you need to do it. This is for a one-off tweak of a file. If you’re doing this in bulk, it’s probably better to use Robocopy with a /copy:T option (see an example here) to copy all the attributes including the time stamp.
(Get-Item "C:\Temp\ITNota.txt").LastWriteTime=("6/1/2022 15:00:00")
Or
(Get-Item "C:\Temp\ITNota.txt").LastWriteTime=("1 June 2022 15:00:00")
Two versions of the script were provided to eliminate ambiguity of the date system. You just need to use one of them.
If you use the US date format, the first one will work. Otherwise, it’s always safer to spell out the date and the month.
Leave a Reply