Modify File Time Stamps using PowerShell

Usages:
(Get-Item [filename]).CreationTime = [date/time]
(Get-Item [filename]).LastAccessTime = [date/time]
(Get-Item [filename]).LastWriteTime = [date/time]

PS C:\> (Get-Item .\test.txt).LastAccessTime = Get-Date
→ This command converts 'last access time' of 'test.txt' to current date and time

PS C:\> (Get-Item .\christmas.tree).LastWriteTime = '2016-12-25 AM0:00'
→ This command converts 'last write time' of 'christmas.tree' to specific date and time
Batch Processing with ForEach:
Get-ChildItem | ForEach-Object { $_.LastWriteTime = Get-Date }

PS C:\> Get-ChildItem | ForEach-Object { $_.LastWriteTime = Get-Date }
→ This command converts 'last write time' to current date and time of all files in working directory

PS C:\> $i = 0; Get-ChildItem | ForEach-Object { $_.LastWriteTime = (Get-Date).AddDays(-1).AddMinutes($i++) }
→ This command converts 'last write time' to yesterday with increasing minutes

One Reply to “Modify File Time Stamps using PowerShell”

Leave a Reply