Unlike batch files (.cmd
, .bat
) associated with cmd.exe
(the legacy Command Prompt), PowerShell's .ps1
script files are by default not directly executable from outside PowerShell.
Instead, they are treated as documents that are by default associated with either Notepad or the (obsolescent) Windows PowerShell ISE, depending on the , and invoking them therefore opens them for editing, which applies to the following contexts:
- Invoking a
.ps1
file from cmd.exe
- Invoking a
.ps1
file from Start Menu's Run
dialog, as in your case (which you can invoke with WinKey+R, for instance)
- Opening (double-clicking) a
.ps1
file from File Explorer or Desktop.
To execute a .ps1
script from outside PowerShell, you must therefore invoke it via PowerShell's CLI, powershell.exe
for Windows PowerShell, pwsh
for PowerShell (Core) 7+.
In the simplest case, using Windows PowerShell and the -File
parameter, as also shown by Mathias R. Jessen in a comment; see the comments below and the linked docs for additional parameters:
# Note:
# * The effective execution policy applies; use -ExecutionPolicy Bypass to bypass.
# * Profiles are loaded; use -NoProfile to suppress.
# * The console window auto-closes when the script terminates; use -NoExit
# to keep the session open.
powershell.exe -File D:\pscript\Intune.ps1
For a comprehensive overview of PowerShell's CLI, see this post.
It is possible - though not advisable - to configure your system to execute .ps1
files by default - see this answer.