Save 10%Pay yearly on any plan. 6% half-yearly, 3% quarterly. Help centreWhatsAppTelegram TeamsOpen a ticket

How to Set .ps1 Files to Open with Windows PowerShell by Default

Windows opens .ps1 scripts in Notepad on purpose. Make a double-click run them in PowerShell, with the correct command line, or use two safer ways.

3 min readBy Swati

Reviewed by the AmazingRDP technical team

Opening .ps1 files with Windows PowerShell by default

Run your scripts on a machine that stays online. A Windows VPS gives you Windows Server with full admin access. See Windows VPS from $8.99

Double-click a .ps1 file and Windows opens it in Notepad. That is not a fault. Microsoft set it up this way so that a script from an email or a download cannot run from one careless click. If you write and run your own scripts every day, you can change it. First, two ways that do not weaken that protection.

Two ways without changing the default

Right-click, Run with PowerShell. Every .ps1 file has this entry in its right-click menu (on Windows 11 under Show more options). The script runs and the window closes when it ends.

A shortcut for one script. Right-click the desktop, choose New, Shortcut, and enter:

powershell.exe -NoExit -ExecutionPolicy Bypass -File "C:\Scripts\backup.ps1"

A double-click on the shortcut runs that one script and keeps the window open. Other scripts still open in Notepad.

Method 1: Open with

  1. Right-click any .ps1 file and choose Open with, Choose another app.
  2. Pick Windows PowerShell. If it is not listed, choose the option to look for an app on the PC and select C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.
  3. Choose Always.

This is the quick way, with one weakness: Windows passes the file's path as a plain command, so a script in a folder with a space in its name, such as C:\My Scripts, fails with an error about an unknown term. Method 2 avoids that.

Method 2: set the command for all users

Open Command Prompt as administrator (not PowerShell; these two commands belong to CMD) and run:

assoc .ps1=Microsoft.PowerShellScript.1
ftype Microsoft.PowerShellScript.1="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -File "%1" %*

-File "%1" hands the script to PowerShell as a file, so spaces in the path are no problem, and %* passes on any extra arguments. Add -NoExit before -File if the window should stay open after the script ends.

If a double-click still opens Notepad, your user account has its own choice stored from an earlier "Open with". It wins over the setting for all users. Do Method 1 once to replace it.

Method 3: the registry

Method 2 writes one registry value. You can set it by hand: in regedit, open HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command and set the (Default) value to:

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -File "%1" %*

Export the key first (File, Export) so that you can restore it.

The script opens and closes, or does not run

A red message that "running scripts is disabled on this system" comes from the execution policy, a separate safety setting. On Windows 10 and 11 it starts as Restricted; on Windows Server as RemoteSigned. To allow your own scripts for your user account:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

With RemoteSigned, scripts you wrote run, and downloaded scripts run only if they are signed or you unblock them yourself (Properties, Unblock).

PowerShell 7

To use PowerShell 7 for the double-click, put its program into the same commands:

ftype Microsoft.PowerShellScript.1="C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -File "%1" %*

Undo it

To send .ps1 files back to Notepad for all users:

ftype Microsoft.PowerShellScript.1="C:\Windows\System32\notepad.exe" "%1"

Think before you do this on a server

After this change, every .ps1 file runs on a double-click, including one you only wanted to read. On a server that other people use, keep the default and use "Run with PowerShell" or shortcuts. On your own Windows VPS the choice is yours. Related guides: set the time zone with PowerShell, enable a port through PowerShell and create a user in Windows Server through CMD.

Questions

Why does my .ps1 file open in Notepad?

By design. Windows opens scripts in an editor so that a script cannot run from an accidental double-click.

How do I run a .ps1 file without changing the default?

Right-click it and choose Run with PowerShell, or run it from a PowerShell window with .\script.ps1.

Why does the script fail when the folder name has a space?

The file association passes the path as a command. Set the command with -File "%1" as shown in Method 2.

Do I need administrator rights?

For Method 2 and the registry, yes. "Open with" changes only your own user account and needs none.