A PowerShell implementation of Touch

Touch is a well known command in the Unix/Linux world. It is used to update the time stamp of files, and additionally will create a new empty file if it doesn’t exist already (unless you use the -c parameter, which will suppress this behaviour).

Invoke-Touch is a PowerShell implementation of Touch, and supports all the functionality of the original command. I have added the Unix/Linux parameter names as aliases, so if you are familiar with touch, you shouldn’t have any problems using this function.

There are however some differences, that I will explain in detail. The first one is that the original command have two different parameters to update the time stamp; -d and -t. In this function I have only one parameter for custom time stamps, but I have added both ‘d’ and ‘t’ as alias for it.

I have seen some specifications of touch where there also are two parameters that lets you set an offset in seconds for the time stamp (-B for positive offset, and -F for negative offset). I have included this functionality in the form of a -OffsetSeconds parameters where you can use positive and negative values to get the same functionality.

I have also added a -PassThru parameter that, when used, will pass the updated ‘fileinfo’ object back to the pipeline for further processing.

NOTE! Invoke-Touch uses Resolve-PathEx internally, and will give you a nasty error if it can’t find it!

I’m not going to go into details of how to use Invoke-Touch as there are tons of pages online that explain how to use the original touch command. You can also use Get-Help to see the internal help for the function.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s