I'm looking for a way to simplify the process of updating the CreationTime and LastWriteTime of files in PowerShell. Currently, I'm using the commands `(Get-Item "file").CreationTime = ("1 November 2025 10:00:00")` and `(Get-Item "file").LastWriteTime = ("1 November 2025 10:00:00")`, but it's tedious because I have to paste the filename in both lines and run them one at a time. It would be great if I could just change the filename once and run a single script to update both timestamps at once!
3 Answers
Here's a simple loop that updates both timestamps for all files in the current directory: `foreach ($file in Get-ChildItem -File) { $file.CreationTime = ("1 November 2025 10:00:00"); $file.LastWriteTime = ("1 November 2025 10:00:00") }`. This way, you can update multiple files at once!
You might also benefit from using `Get-ChildItem -File` to handle multiple files more easily if that's what you need.
You can use a one-liner like this: `(Get-Item "file") | % {$_.CreationTime = $_.LastWriteTime = ("1 November 2025 10:00:00")}`. This will set both timestamps in one go! Just replace "file" with your file name.
Perfect, thank you so much!
Just a couple of tips: 1. You don't need the parentheses around `Get-Item`; it doesn't add any value here. When updating many files, it could even slow things down a bit. 2. Also, you might want to format the command correctly so it shows `$_` properly instead of `$`.

What about the total editing time for a Word document? Is there a way to change that too?