PSTouch.psm1
function Touch { <# .SYNOPSIS Mimics the Linux 'touch' command by creating a file or updating a file's last modified timestamp. .DESCRIPTION This function checks if the specified file exists. - If the file exists, it updates its LastWriteTime. - If the file does not exist, it creates an empty file. .PARAMETER Path The path to the file to be touched. If not specified, the current directory is used. .EXAMPLE PS> touch C:\logs\app.log - Creates an empty file named 'app.log' in the 'C:\logs' directory if it does not exist. .EXAMPLE PS> touch C:\logs\app.log - Updates the LastWriteTime of 'app.log' if it already exists. .NOTES Author: Inspyre-Softworks Version: 1.0.0 PowerShell Version: 5.1 .LINK https://www.powershellgallery.com/packages/PSTouch #> param ( [Parameter(Mandatory = $true, Position = 0, HelpMessage = 'Path to the file to touch.')] [string]$Path ) if (Test-Path $Path) { (Get-Item $Path).LastWriteTime = Get-Date } else { New-Item -ItemType File -Path $Path -Force | Out-Null } } Set-Alias touch Touch Export-ModuleMember -Function Touch |