CreateFile.ps1 (660B)
1 [CmdletBinding()] 2 param( 3 [Parameter(Mandatory=$true, 4 ValueFromPipeline=$true, 5 ValueFromPipelineByPropertyName=$true)] 6 [String]$path='$env:USERPROFILE', 7 [int] $name = 'text.txt' 8 ) 9 Write-Host "Creating $name..." -ForegroundColor Gray 10 if (!(Test-Path "$path/$name")) { 11 New-Item $path/$name -ItemType file | Out-Null 12 Write-Host "$name created in $path" -ForegroundColor Green 13 } else { 14 Write-Host "$name already exists in $path" -ForegroundColor Yellow 15 Write-Host "Did not create $name" -ForegroundColor Red 16 }