Linux has Touch. I needed touch today in PowerShell. This is what I came up with.
function touch {
param (
[Parameter(Mandatory=$true, ValueFromRemainingArguments=$true)]
[string[]]$Paths
)
foreach ($Path in $Paths) {
$dir = Split-Path $Path
if (-not (Test-Path $dir)) {
New-Item -ItemType Directory -Path $dir -Force | Out-Null
}
if (-not (Test-Path $Path)) {
New-Item -ItemType File -Path $Path -Force | Out-Null
}
}
}
Add it to your PowerShell profile by pasting the function into your current PowerShell window then:
touch $PROFILE
notepad $PROFILE
Paste the function into the text file and save it. Then all future PowerShell sessions can use:
touch <path to your file>
One thing I built into it was to build out the intermediary folders in case they don't exist.