A .ps1 file runs by typing .\filename.ps1 in PowerShell, by using the Run with PowerShell context menu, or from CMD with the -File flag.
Double-clicking a .ps1 file opens it in Notepad by default, not the PowerShell engine. This guide covers exactly how to execute a .ps1 file on Windows, with steps for PowerShell, CMD, and the right-click menu. You will also learn what to do when execution policy blocks the script and how to work with scripts that contain spaces in their path.
The Three Main Ways to Run a .ps1 Script
Each method handles a different situation — running a script in the current folder, launching it from a different directory, or bypassing the execution policy for a single session. This section lays out all three before you choose one.
From Within PowerShell (the Standard Method)
Open PowerShell and navigate to the folder that contains your script. Type .\YourScript.ps1 and press Enter. The .\ prefix is required — typing only the file name produces an error because Windows treats bare filenames as commands, not scripts.
If the script lives in a subfolder of the current directory, use a relative path like .\SubFolder\YourScript.ps1. For scripts stored elsewhere, provide the full path: C:\Scripts\YourScript.ps1. Quotation marks are required around any path that contains spaces: & "C:\My Scripts\YourScript.ps1".
From CMD or the Run Dialog
Launch Command Prompt or press Win + R and type the powershell executable followed by the -File parameter and the script path: powershell -File C:\Scripts\YourScript.ps1. If the path contains spaces, wrap it in quotes: powershell -File "C:\My Scripts\YourScript.ps1".
To keep the PowerShell window open after the script finishes (useful for seeing error output), add the -noexit flag: powershell -noexit -File "C:\My Scripts\YourScript.ps1".
Using the “Run with PowerShell” Context Menu
Right-click the .ps1 file in File Explorer and select Run with PowerShell. This launches the script under the current execution policy without requiring you to open a terminal first. The window closes automatically when the script finishes.
How Do You Handle Execution Policy Blocks?
Execution policy is a Windows security feature that controls whether scripts can run. The default setting on most Windows systems is Restricted (no scripts run) or RemoteSigned (local scripts run, downloaded ones require a digital signature). When a script fails with a red permission error, the policy is the usual cause.
The safest workaround is a per-session bypass that does not change your system-wide policy. From CMD or the Run dialog, use: powershell -ExecutionPolicy Bypass -File "C:\Scripts\YourScript.ps1". This lets you run the script that one time without lowering security for all future sessions.
If you need to change the policy permanently for your user account, open PowerShell as Administrator and run: Set-ExecutionPolicy RemoteSigned. Microsoft’s Set-ExecutionPolicy documentation confirms that execution policy is a helpful security layer, not a complete security boundary.
Running a Script on a Remote Computer
For scripts that need to execute on one or more remote machines, use Invoke-Command with the -FilePath parameter: Invoke-Command -ComputerName RemotePC -FilePath C:\Scripts\YourScript.ps1. The script file must be accessible locally on the target machine or available over a network path the remote computer can reach.
| Method | Command or Action | Best For |
|---|---|---|
| PowerShell (current dir) | .\YourScript.ps1 |
Scripts in the folder you are already in |
| PowerShell (full path) | C:\Scripts\YourScript.ps1 |
Scripts stored in a different folder |
| CMD or Run dialog | powershell -File "path" |
Launches from outside PowerShell |
| CMD + bypass policy | powershell -ExecutionPolicy Bypass -File "path" |
One-time script run without changing policy |
| Context menu | Run with PowerShell (right-click) | Quick ad-hoc run, no terminal typing |
| Remote execution | Invoke-Command -FilePath |
Running scripts on other machines |
| Quoted paths with spaces | & "C:\My Scripts\Script.ps1" |
Any path containing spaces |
What Is the Correct Syntax — and the One Mistake to Avoid
The most common error when executing a .ps1 file is entering the bare filename without .\ when the script sits in the current directory. .\ tells PowerShell to look in the current folder. Without it, PowerShell tries to interpret YourScript.ps1 as a command and returns an error.
Another frequent mistake is forgetting that paths with spaces need quotes. A script at C:\My Scripts\Test.ps1 must be wrapped in quotation marks whether you use PowerShell or CMD.
Differences Between PowerShell 5.1 and PowerShell 7+
Windows ships with Windows PowerShell 5.1, launched with powershell. PowerShell 7 and later are separate installs launched with pwsh. Both use the same .\ and -File syntax, but only pwsh provides features from the modern cross-platform version. If you are unsure which version is installed, run $PSVersionTable.PSVersion in any PowerShell console to check the version number.
| Executable | Version | Install Location |
|---|---|---|
powershell |
Windows PowerShell 5.1 | Built into Windows |
pwsh |
PowerShell 7+ | Separate install (Microsoft Store or GitHub) |
Checklist for a Successful .ps1 Run
When a script refuses to run, verify these four points in order. The first two fix the vast majority of failures.
- Is the policy blocking you? Run
Get-ExecutionPolicyin PowerShell. If it returns Restricted, use the per-session bypass (-ExecutionPolicy Bypass) or change the policy with Set-ExecutionPolicy RemoteSigned from an Administrator console. - Did you use
.\? When the script is in the current folder, always prefix with.\— bare filenames fail. When using a full path, no prefix is needed. - Are spaces quoted? Any path containing a space must be wrapped in double quotes, and the call operator
&may be required in PowerShell:& "C:\My Scripts\Script.ps1". - Is the file unblocked? Scripts downloaded from the internet may have a zone identifier that blocks execution under RemoteSigned. Right-click the file in File Explorer, choose Properties, and check Unblock at the bottom of the General tab if it appears.
References & Sources
- Microsoft Learn. about_Scripts Official documentation covering script execution syntax,
.\prefix, and full-path invocation. - Microsoft Learn. Set-ExecutionPolicy Policy values, scope options, and security considerations.
