I added a new system environment variable with a link to my ps1 file.
From outside of PowerShell its scripts (*.ps1) are by design not directly executable (unlike batch files (*.cmd, *.bat), so making *.ps1 scripts available via $env:PATH is not sufficient if you want to call them from cmd.exe
However, you can write a simple, auxiliary wrapper batch file that invokes your script explicitly via powershell.exe:
In one of the folders listed in $env:PATH:
create batch file CF.cmd with the following content:
@powershell.exe -NoProfile -File "%~dp0CreateFile.ps1" %*
copy CreateFile.ps1 to the same folder, but remove the function wrapper so that the calling the script invokes the functionality directly; i.e., make its content the following:
param($FileName)
New-Item -Name $FileName -ItemType File
You will then be able to call CF (CF.cmd) from both cmd.exe and PowerShell.
From within PowerShell, however, calling CreateFile (CreateFile.ps1) directly is more efficient.