How to run a .ps1 file in PowerShell

To run a PowerShell script file (.ps1), you type the full path to the file into PowerShell and press Enter. On Windows 10 and 11, the simplest way is to open PowerShell, type a dot, a backslash, and the filename — for example, .\myscript.ps1 — then press Enter. If the file is in a different folder, you need the full path: C:\Users\YourName\Documents\myscript.ps1.

PowerShell will refuse to run scripts by default on most Windows machines. If you see an error message that says "cannot be loaded because running scripts is disabled on this system," you have hit the execution policy — a safety feature that prevents accidental or malicious scripts from running. You can change this setting, but it requires understanding what you are allowing.

The steps below cover how to check your current policy, how to change it safely, and how to run your script once the policy is set. You will also learn where PowerShell looks for files and what to do if the path contains spaces.

Key Takeaways

  • PowerShell scripts are text files that end in .ps1 and contain commands that PowerShell will run in order.
  • By default, Windows blocks .ps1 files from running to prevent malicious code — you must change the execution policy before your script will work.
  • The safest execution policy for personal use is RemoteSigned, which allows scripts you create locally but blocks downloaded scripts unless you unblock them first.
  • You run a script by typing its path into PowerShell: either .\filename.ps1 if it is in your current folder, or the full path if it is elsewhere.
  • If your script path contains spaces, wrap the entire path in quotes: "C:\Program Files\myscript.ps1".

Understanding the execution policy and why it exists

The execution policy is a PowerShell setting that controls whether scripts can run at all. It is not a permission system — it does not prevent you from running scripts you own, and it does not stop a malicious program from running code if it has already infected your machine. Instead, it is a guard against accidentally running a script you downloaded or received from someone else without reading it first.

Windows comes with the execution policy set to Restricted, which means no scripts run, period. This is the safest default. When you try to run a .ps1 file and see the error "cannot be loaded because running scripts is disabled," that is the Restricted policy at work.

There are five execution policies you might encounter. Restricted blocks all scripts. AllSigned allows only scripts signed with a digital certificate. RemoteSigned allows scripts you create locally, but blocks downloaded scripts unless you explicitly unblock them. Unrestricted allows all scripts with a warning. Bypass allows all scripts with no warning at all. For personal use on your own machine, RemoteSigned is the standard choice — it gives you the freedom to run your own work while keeping a basic safety net in place.

Checking your current execution policy

Before you change anything, check what policy is currently set. Open PowerShell (search for "PowerShell" in the Windows Start menu, then click "Windows PowerShell" or "PowerShell"). Type this command and press Enter:

Get-ExecutionPolicy

PowerShell will print one word: Restricted, AllSigned, RemoteSigned, Unrestricted, or Bypass. If it says Restricted or AllSigned, you will need to change it before your script runs. If it says RemoteSigned or higher, you can skip to the section on running your script.

Note that execution policy can be set at different levels — for your user account only, for all users on the machine, or for the current PowerShell session only. The command above shows the policy that applies to you right now. If you want to see all the policies set at each level, type Get-ExecutionPolicy -List instead.

Changing the execution policy to RemoteSigned

To change your execution policy to RemoteSigned, type this command into PowerShell and press Enter:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

PowerShell will ask you to confirm. Type Y and press Enter. The change takes effect when ready. You only need to do this once — the policy stays set until you change it again.

The -Scope CurrentUser part means the policy applies only to your user account, not to other people who log into this machine. If you are the only user, this does not matter. If others use the computer, they will need to set their own policy if they want to run scripts.

If you do not have administrator rights on your machine, you can still set the policy for your user account. If you want to set it for all users on the machine, you would need to run PowerShell as administrator and use -Scope LocalMachine instead — but for most home and personal setups, CurrentUser is what you want.

Running your script from PowerShell

Once the execution policy is set, navigate to the folder where your script lives. You can do this by typing cd followed by the folder path. For example, if your script is in Documents:

cd C:\Users\YourName\Documents

Then type the script name with a dot and backslash in front:

.\myscript.ps1

Press Enter. PowerShell will run the script line by line. Any output the script produces will print to the screen. If the script has errors, PowerShell will stop and show you the error message.

If your script is in a different folder and you do not want to navigate there first, you can type the full path instead:

C:\Users\YourName\Documents\myscript.ps1

If the path contains spaces — for example, C:\Program Files\My Scripts\myscript.ps1 — wrap the entire path in double quotes:

"C:\Program Files\My Scripts\myscript.ps1"

What to do if your script is blocked

If you downloaded a script from the internet and changed the execution policy to RemoteSigned, PowerShell may still refuse to run it. This happens because Windows marks downloaded files as "coming from the internet" and RemoteSigned blocks those by default.

To unblock a single script, right-click the .ps1 file in File Explorer, click Properties, and look for a checkbox at the bottom that says "Unblock." Check it and click OK. Then try running the script again.

If you want to unblock the script from PowerShell instead, navigate to the folder where it lives and type:

Unblock-File -Path .\myscript.ps1

Only unblock scripts you trust. If someone sent you a script and you are not sure what it does, open it in a text editor first (right-click, choose "Open with," then Notepad) and read through the commands. PowerShell scripts are plain text, so you can see exactly what they will do before you run them.

Understanding where PowerShell looks for files

When you type a command into PowerShell, it searches for that command in a specific order. First, it looks in the current folder (the one you are in right now). Then it looks in folders listed in your PATH — a list of directories where Windows stores programs and tools.

This is why you need the dot and backslash (.\) in front of your script name. Without it, PowerShell assumes you are looking for a program, not a script in the current folder. If you type just myscript.ps1, PowerShell will search your PATH and probably not find it, even if the file is right there in your current folder.

The dot means "current folder" and the backslash is the path separator. So .\myscript.ps1 tells PowerShell: "Run the file called myscript.ps1 in the folder I am in right now."

Frequently Asked Questions

Can I run a PowerShell script by double-clicking it in File Explorer?

No. Double-clicking a .ps1 file opens it in Notepad or your default text editor instead of running it. You must open PowerShell and type the command yourself, or create a batch file (.bat) that calls PowerShell to run the script. The batch file approach is more complex and not needed for personal use.

What does "execution policy" actually prevent?

It prevents scripts from running, but only if you try to run them directly. It does not stop malware or prevent a program from executing code. It is a friction point designed to make you think before you run a script you did not write. If malicious code is already on your machine, changing the execution policy will not protect you.

Is it safe to set the execution policy to Unrestricted or Bypass?

Unrestricted and Bypass remove the safety check entirely. For personal use on your own machine, RemoteSigned is safer because it still blocks downloaded scripts unless you explicitly unblock them. Only use Unrestricted or Bypass if you have a specific reason and understand the trade-off.

Why does my script run but produce no output?

The script ran successfully — it just did not print anything to the screen. Many scripts do their work silently. If you want to see what the script is doing, open it in a text editor and look for commands that produce output, like Write-Host or Write-Output. You can also add these commands yourself to print status messages.

Can I run a PowerShell script on a Mac or Linux machine?

Yes, if you install PowerShell Core, which is a cross-platform version of PowerShell. The steps are the same: set the execution policy and run the script with .\filename.ps1. However, file paths use forward slashes on Mac and Linux instead of backslashes, so you would type ./myscript.ps1 instead.