17

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.

21

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)
6

The following way explained here works for me. So I used:

Get-ChildItem  C:\testFile1.txt | % {$_.LastWriteTime = '01/11/2005 06:01:36'}

Do not get confused by the "get-*" command... it will work regardless that it is a get instead of write or something. Keep also noted as written in the source that you need to use YOUR configured data format and maybe not the one in my example above.

4

Yes, it is possible to change the last modified date. Here is a one liner example

powershell foreach($file in Get-ChildItem folder1) {$(Get-Item $file.Fullname).lastwritetime=$(Get-Date).AddHours(-5)}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.