Running a .ps1 file in PowerShell
To run a PowerShell script file (.ps1), you type the full path to the file at the PowerShell prompt, preceded by a dot and a space. If your script is named myscript.ps1 and sits on your Desktop, you would type: . C:\Users\YourUsername\Desktop\myscript.ps1 and press Enter. The dot tells PowerShell to execute the file in the current session.
The most common reason a script will not run is that PowerShell's execution policy blocks it. By default, Windows prevents unsigned scripts from running as a safety measure. You may see an error like "cannot be loaded because running scripts is disabled on this system." This is not a permanent block — it is a setting you can change for your user account or for a single session.
Key Takeaways
- Run a script by typing a dot, a space, and the full path to the .ps1 file at the PowerShell prompt.
- If you get an execution policy error, you can allow scripts to run for your user account by running Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser once.
- To run a script just once without changing your execution policy, use powershell -ExecutionPolicy Bypass -File "C:\path\to\script.ps1" in Command Prompt or Run.
- Scripts you write yourself or download from trusted sources are safe to run; the policy exists to block scripts from unknown origins.
Understanding execution policy and why scripts are blocked
PowerShell's execution policy is a safety feature that prevents malicious scripts from running without your knowledge. When you download a file from the internet, Windows marks it as coming from an untrusted source. PowerShell checks this mark before running any script file.
There are four execution policies you will encounter: Restricted (the default on most Windows machines) blocks all scripts; RemoteSigned allows scripts you create locally but blocks downloaded scripts unless they are signed with a digital certificate; Unrestricted allows all scripts but warns you before running downloaded ones; and Bypass allows everything with no warnings. For everyday use, RemoteSigned is the right choice — it protects you from downloaded malware while letting you run your own work.
Changing execution policy for your user account
To allow scripts to run permanently for your user account, open PowerShell and run this command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
PowerShell will ask you to confirm. Type Y and press Enter. This change applies only to your user account and only to PowerShell — it does not affect Command Prompt or other programs. You only need to run this command once; the setting persists until you change it again.
If you want to change the policy back to the default later, run the same command but replace RemoteSigned with Restricted. You can also check your current execution policy at any time by typing Get-ExecutionPolicy.
Running a script without changing your execution policy
If you do not want to change your execution policy, you can run a single script with the policy bypassed for that one time. Open Command Prompt (not PowerShell) and type:
powershell -ExecutionPolicy Bypass -File "C:\full\path\to\your\script.ps1"
Replace the path with the actual location of your script file. This command starts PowerShell, tells it to ignore the execution policy for this session only, runs your script, and then closes. The next time you open PowerShell normally, the policy is back to its original setting.
This method is useful if you want to run a script once or twice without making a permanent change to your system. It is also the safest approach if you are running a script you are not completely sure about — you can test it in a limited way without opening up your system permanently.
Making sure PowerShell can find your script file
PowerShell needs the full path to your script unless the file is in the current directory. If you are not sure what the current directory is, type pwd at the PowerShell prompt to see it. If your script is in that folder, you can run it with just the filename: . .\myscript.ps1
If your script is somewhere else, use the full path starting from the drive letter. For a file on your Desktop, that would be C:\Users\YourUsername\Desktop\myscript.ps1. For a file in Documents, it would be C:\Users\YourUsername\Documents\myscript.ps1. You can also drag the script file into the PowerShell window after typing the dot and space — PowerShell will paste the full path automatically.
Removing the mark that Windows puts on downloaded scripts
If you download a script from the internet and want to run it, Windows attaches metadata marking it as untrusted. Even with RemoteSigned policy, PowerShell will block it. You can remove this mark before running the script.
Right-click the .ps1 file and select Properties. At the bottom of the General tab, you will see a checkbox that says "Unblock" with text saying the file came from another computer. Check that box and click Apply, then OK. Now the file is no longer marked as untrusted, and PowerShell will run it if your execution policy allows local scripts.
Alternatively, you can unblock a script from PowerShell itself by running: Unblock-File -Path "C:\path\to\script.ps1"
Troubleshooting common errors when running scripts
If you see "The term 'myscript.ps1' is not recognized as the name of a cmdlet," you forgot the dot and space at the beginning. PowerShell thought you were asking it to run a command, not a file. Add the dot and space: . C:\path\to\myscript.ps1
If you see "cannot be loaded because running scripts is disabled," your execution policy is set to Restricted. Use one of the methods above to either change your policy or bypass it for that session.
If you see "The file does not exist," check that the path is correct. Spaces in folder names are fine as long as the path is in quotes. A common mistake is typing the path without quotes when it contains spaces: . "C:\Program Files\My Scripts\myscript.ps1" works, but . C:\Program Files\My Scripts\myscript.ps1 does not.
Frequently Asked Questions
What is the difference between running a script with a dot and running it without?
The dot tells PowerShell to run the script in the current session, so any variables or functions the script creates stay available afterward. Without the dot, PowerShell runs the script in a separate session, and everything it creates disappears when the script ends. For most everyday use, include the dot.
Is it safe to change my execution policy to RemoteSigned?
Yes. RemoteSigned still protects you from downloaded scripts unless they are digitally signed. It only allows scripts you create yourself or that come from a trusted source with a valid signature. You are not opening yourself to malware by using this policy.
Can I run a PowerShell script by double-clicking it?
No. Double-clicking a .ps1 file opens it in Notepad or your default text editor instead of running it. You must run it from PowerShell or Command Prompt using the methods described here. This is intentional — it prevents accidental execution of scripts you did not mean to run.
Do I need to change my execution policy if I only run scripts I write myself?
If you write the script yourself on your own computer, you only need to change your policy once to RemoteSigned. After that, all scripts you create locally will run without further changes. You only need to use the bypass method if you are running downloaded scripts and do not want to unblock them individually.