How To Execute A PS1 File In PowerShell | Policy Fix

To execute a .ps1 file in PowerShell, type the full or relative path to the script (e.g., .\MyScript.ps1) and press Enter.

Most Windows users who double‑click a .ps1 file get a text editor instead of a running script. The reason is simple: PowerShell doesn’t treat plain filenames as executable by default, and an execution‑policy setting often blocks scripts entirely. The fix takes two steps – one right path, one policy change – and you’ll be running scripts in under a minute.

What Is a .ps1 File?

A .ps1 file is a plain‑text file that contains PowerShell commands, saved with the .ps1 extension. Think of it as a batch file for PowerShell. It can include logic, loops, and calls to cmdlets, and it runs from the command line or from within the PowerShell environment. Microsoft’s own definition calls it a “PowerShell script” – just a text file you can execute to automate tasks.

The Standard Way to Run a .ps1 Script

If you’re already inside PowerShell, run a script by providing its path. The safest method is to use the full path, but a relative path works if you’re in the script’s directory. For a script named Get-ServiceLog.ps1 in C:\Scripts, you would type:

C:\Scripts\Get-ServiceLog.ps1

When you’re inside the script’s folder, use the current‑directory prefix .\:

.\Get-ServiceLog.ps1

PowerShell interprets .\ as “look in the current folder.” If the path contains spaces, wrap it in quotes and use the call operator &:

& "C:\My Scripts\Get-UserInfo.ps1"

This pattern is documented on Microsoft’s about_Scripts page. Once the path is correct, the script runs immediately – unless the execution policy blocks it.

Handling the Execution Policy

Windows enforces a security layer called the execution policy. By default, it’s set to Restricted on many systems, which prevents any .ps1 file from running. You must change the policy to allow script execution before the first script will work.

The two common safe policies are RemoteSigned and AllSigned. RemoteSigned lets locally created scripts run freely and requires downloaded scripts to be signed by a trusted publisher. AllSigned requires every script to be signed. For most users, RemoteSigned is the recommended choice.

To set it, open PowerShell as Administrator (right‑click the Start menu, select “Windows PowerShell (Admin)” or “Terminal (Admin)”), then run:

Set-ExecutionPolicy RemoteSigned

Press Y when prompted. The change takes effect immediately. If you don’t have admin rights, you can set the policy for only your user account using the -Scope CurrentUser parameter:

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

Microsoft’s Set-ExecutionPolicy documentation explains the full list of options and scopes.

Method Command / Action Notes
Full path in PowerShell C:\Scripts\MyScript.ps1 Works from any directory
Relative path in same folder .\MyScript.ps1 Requires .\ prefix
Path with spaces & "C:\My Scripts\MyScript.ps1" Use call operator and quotes
From Command Prompt (CMD) powershell -File C:\Scripts\MyScript.ps1 Launches PowerShell, runs script, then closes
File Explorer right‑click Run with PowerShell Available since PowerShell 3.0; may fail if policy is restricted

Common Mistakes and How to Fix Them

The most frequent error is typing just the filename without the .\ prefix while in the script’s folder. PowerShell treats MyScript.ps1 as a command name, not a file path, and returns a “cannot find” error. The fix: always use .\ when running from the current directory.

Another common mistake is forgetting to adjust the execution policy. Even if you type the path correctly, a restricted policy will block the script. If you see “running scripts is disabled on this system,” run the Set-ExecutionPolicy command shown above.

If you’re running from Command Prompt, don’t try to type just the .ps1 filename – CMD doesn’t know how to run PowerShell scripts. Use the powershell -File syntax instead. And remember: when changing the execution policy for the LocalMachine scope, you must start PowerShell with “Run as administrator,” or the change will be silently ignored.

How Do I Execute a PS1 File Without Admin Rights?

If you don’t have administrator access, you can still run scripts by setting the execution policy at the CurrentUser scope. Use the command Set-ExecutionPolicy -Scope CurrentUser RemoteSigned. This only affects your account and doesn’t require elevation. Once set, you can run scripts with the same path syntax. Keep in mind that some scripts that modify system settings may still fail without admin rights – that’s a permissions limitation, not a policy one.

Safety and Compatibility Notes

Execution policy is a security feature, not a permissions system. It’s designed to prevent unintentional script execution. Microsoft recommends RemoteSigned for most users. Avoid setting Unrestricted because it bypasses all checks and can leave you vulnerable to malicious scripts. If you frequently run scripts from trusted sources, AllSigned provides the strongest protection.

For remote execution, you can use Invoke-Command with the -FilePath parameter to run a local .ps1 file on a remote machine, but the script file must be accessible to the local computer.

Policy Behavior How to Set
Restricted Blocks all .ps1 scripts (default) No change needed
RemoteSigned Allows local scripts; downloaded scripts must be signed Set-ExecutionPolicy RemoteSigned
AllSigned Requires all scripts to be signed by a trusted publisher Set-ExecutionPolicy AllSigned
Bypass Nothing is blocked (not recommended for regular use) Set-ExecutionPolicy Bypass

The Step‑by‑Step Checklist

  1. Open PowerShell (run as Administrator if you plan to change the machine‑wide policy).
  2. Run Set-ExecutionPolicy RemoteSigned (or -Scope CurrentUser if you lack admin rights).
  3. Navigate to the folder containing your .ps1 file, or use the full path.
  4. Type .\YourScript.ps1 (if in the same folder) or the full path, and press Enter.
  5. The script runs immediately. If you see errors, double‑check the path and ensure the execution policy change took effect.

That’s all it takes. Once you’ve set the policy and used the right syntax, every .ps1 file runs the same way – a clean, repeatable process that works on any Windows system.

References & Sources

  • Microsoft Learn. “about_Scripts” Official documentation covering .ps1 file format, execution syntax, and policy requirements.