Changing last modified date or time via PowerShell

powershell

Is it possible to change a file or folders last modified date/time via PowerShell?

I have a folder folder1/ and I want to change the last modified date and time of that folder and it's contents via PowerShell.

Best Answer

Get the file object then set the property:

$file = Get-Item C:\Path\TO\File.txt
$file.LastWriteTime = (Get-Date)

or for a folder:

$folder = Get-Item C:\folder1
$folder.LastWriteTime = (Get-Date)
Related Question