PowerShell script files, across all versions, use the .ps1 filename extension.
From within PowerShell, you can invoke them directly, e.g., .\script.ps1
- Note that, unlike in
cmd.exe, you must use .\ (or a full path) in order to execute a file located in the current directory - just script.ps1 won't work - see this answer for background information.
From cmd.exe, you must use PowerShell's CLI (powershell.exe in Windows PowerShell / pwsh in PowerShell [Core] v6+) in order to execute a script file:
powershell.exe -File script.ps1
pwsh -File script.ps1 (-File may be omitted)
Note that with -File the .\-prefix is not required.
However, if you use -Command (-c) instead (which is the default with powershell.exe, whereas pwsh now defaults to -File), you do need the .\, because the -Command argument(s) are interpreted as a piece of PowerShell code, i.e. as if you had submitted it inside a PowerShell session.
You've discovered this in your own answer, where you pass a PowerShell command directly to the (implied) -Command parameter.
Note, however, that it's better to double-quote such commands, so as to prevent cmd.exe from interpreting certain characters itself, which breaks the call.
For instance, the following call would break, if you didn't enclose the -Command (-c) argument in "...":
# From cmd.exe; "..." required.
C:\>powershell.exe -c "Write-Output 'a & b'"
a & b
Another important consideration is that you need to escape embedded " chars. as \" for the CLI (even though PowerShell-internally you would use `" or ""):
# From cmd.exe; note the inner " escaped as \"
C:\>powershell.exe -c "Write-Output \"hi there\""
hi there
powershell yourfilename.ps1Typepowershell /?from a command prompt for more information.Data.ps1. Error isThe term 'Data.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + Data.ps1 + ~~~~~~~~ + CategoryInfo : ObjectNotFound: (Data.ps1:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundExceptionpowershell .\Data.ps1, Error is.\Data.ps1 : File D:\GuiGuiRenderer\Build\GuiGUiBuild\Data.ps1 cannot be loaded. The file D:\GuiGuiRenderer\Build\GuiGUiBuild\Data.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1 + .\Data.ps1 + ~~~~~~~~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccesspowershell data.ps1will work fine. If you're getting different results, then edit your question to include exactly what you're running at the command line. If you're not running it from the command line, then include details of exactly how you're trying to run it, including any batch file code if relevant. Expecting us to read your mind to find out what the problem is won't work.