Update last modified date to current date for all items in a directory using powershell

The title says it all.  It’s incredibly simple:

gci | %{$_.LastWriteTime = date}

gci is shorthand for Get-ChildItem, and % is shorthand for ForEach-Object.  $_ refers to the current element being iterated over.  Date returns the current date (and time).

The script therefore gets all items (in the context of the current directory) and updates the LastWriteTime for them all to the current date.  Sorted.

Leave a Reply

Your email address will not be published. Required fields are marked *