Touching a file using Windows PowerShell

Its been a little while since I’ve posted on my blog…it’s been a very hectic few months but I’m back and hopefully will be able to provide you guys with some more useful SCOM related things.

Today though its Windows PowerShell as I was required to perform the equivalent of touching a file on a Windows Server. PowerShell doesn’t have a cmdlet specifically for this (that I’m aware of anyway) but we can use the Set-ItemProperty cmdlet and have it update the LastWriteTime property using the current date and time (well actually you could pass it any date and time if you like).

Turns out its pretty easy, just like this…

Set-ItemProperty -Path C:\TestFile.txt -Name LastWriteTime -Value (Get-Date)


Hope it helps you.

Leave a Reply

Your email address will not be published.