How to Run a .ps1 File in PowerShell
PowerShell scripts — saved with the .ps1 file extension — are powerful automation tools built into Windows. But if you've ever double-clicked a .ps1 file and nothing happened, or tried to run one and hit an error, you're not alone. Running a PowerShell script isn't quite as straightforward as launching a regular program, and that's by design.
What Is a .ps1 File?
A .ps1 file is a plain-text script written in the PowerShell scripting language. It can contain anything from a single command to hundreds of lines of logic — automating backups, managing users, configuring system settings, or pulling data from APIs.
Windows doesn't run these files on double-click by default. Instead, it opens them in a text editor. This is a deliberate security measure, not a bug.
Why PowerShell Blocks Scripts by Default
PowerShell uses a setting called the Execution Policy to control whether scripts can run on a system. Out of the box, most Windows machines are set to Restricted, which blocks all .ps1 files from executing — even ones you wrote yourself.
The four most common execution policy levels are:
| Policy | What It Allows |
|---|---|
Restricted | No scripts. Interactive commands only. |
AllSigned | Scripts must be signed by a trusted publisher. |
RemoteSigned | Local scripts run freely; downloaded scripts must be signed. |
Unrestricted | All scripts run, with warnings for downloaded files. |
Most users working with their own scripts set the policy to RemoteSigned, which strikes a practical balance between usability and security.
How to Check Your Current Execution Policy
Before running any script, open PowerShell and type:
Get-ExecutionPolicy This tells you what's currently active. If it returns Restricted, you'll need to change it before your script will run.
How to Change the Execution Policy
Open PowerShell as Administrator (right-click the Start menu → Windows PowerShell (Admin) or Terminal (Admin)), then run:
Set-ExecutionPolicy RemoteSigned Confirm when prompted. You only need to do this once per machine — the setting persists.
⚠️ If you're on a managed corporate or school machine, your IT department may enforce a policy via Group Policy that overrides any change you make here.
Methods for Running a .ps1 File
Once your execution policy allows it, there are several ways to actually execute a script.
Method 1: Run From Within PowerShell
Navigate to the folder containing your script, then call it with a . prefix:
cd C:Scripts .myscript.ps1 The . prefix tells PowerShell to look in the current directory. Without it, PowerShell won't find the file even if you're in the right folder.
Method 2: Use the Full File Path
You can run a script from anywhere by specifying its full path:
& "C:Scriptsmyscript.ps1" The & (call operator) is especially useful when the path contains spaces.
Method 3: Right-Click → Run with PowerShell
In File Explorer, right-click a .ps1 file and choose Run with PowerShell. This works if your execution policy permits it, but the window often closes immediately after the script finishes — making it harder to catch errors or output.
Method 4: Run With Bypass for a Single Session
If you don't want to change the system-wide execution policy, you can bypass it for a single script execution:
PowerShell -ExecutionPolicy Bypass -File "C:Scriptsmyscript.ps1" This runs the script without modifying any persistent settings — useful for one-off situations or running scripts from a batch file.
Passing Parameters to a .ps1 Script 🛠️
Many scripts are written to accept input. If a script has defined parameters, you pass them after the filename:
.myscript.ps1 -Username "jsmith" -LogPath "C:Logs" What parameters a script accepts depends entirely on how it was written. Open the file in a text editor to check for a param() block near the top.
Common Errors and What They Mean
"cannot be loaded because running scripts is disabled on this system" Your execution policy is blocking the script. Adjust it using Set-ExecutionPolicy.
"is not recognized as the name of a cmdlet" You likely didn't include the . prefix, or you're not in the right directory.
"Access to the path is denied" The script requires Administrator privileges. Re-open PowerShell as Admin.
"File cannot be loaded. The file is not digitally signed." Your policy is set to AllSigned or RemoteSigned and the script lacks a valid signature. Either sign the script or adjust the policy for local files.
The Variables That Affect Your Specific Situation
How you run a .ps1 file — and whether it runs successfully — depends on factors specific to your environment:
- Windows version: PowerShell 5.1 comes built into Windows 10/11; PowerShell 7+ is a separate install with some behavioral differences
- Who manages the machine: Personal machines give you full control; domain-joined or managed devices may lock down execution policies entirely
- Script source: Scripts you wrote yourself behave differently under
RemoteSignedthan scripts downloaded from the internet, which carry a hidden Zone Identifier mark - Privilege requirements: Some scripts need Admin rights; others run fine as a standard user
- PowerShell version: A script written for PowerShell 7 may use features not available in 5.1, and vice versa
Running the same .ps1 file on a personal laptop versus a work computer versus a server can produce completely different outcomes — even with identical commands. Your specific combination of OS version, policy settings, user permissions, and script requirements is what ultimately determines the path you'll need to take.