When you double-click a .ps1 file from File Explorer, Windows 10 will open it in Notepad rather than executing the script with PowerShell. If you want to set .ps1 script to open with PowerShell by default, you have to change the file type association.
Method 1: Associate .PS1 to Open in PowerShell
- Right-click any .ps1 file in File Explorer, and then select Open with from the context menu.
- If the PowerShell program isn’t listed, click on More apps.
- Check the box labeled “Always use this app to open .ps1 files“, and click on “Look for another app on this PC“.
- When the Open with dialog box appears, drill down to the directory C:\Windows\System32\WindowsPowerShell\v1.0 and select the powershell.exe file. Click Open.
- Now you’ve successfully set PowerShell as the default program for opening .ps1 file type.
Method 2: Change Default Program for Opening PowerShell Script
Need to associate all types of PowerShell script (.ps1, .psm1, .psd1, etc.) to open with PowerShell by default? You can do it with a simple registry tweak.
- Open the Registry Editor. Copy the following line and paste it into the address bar, then press Enter.
HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command
Next, double-click the (Default) value in the right pane.
- In the Edit String window, copy and paste the following command into the Value data field. Click OK.
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "%1"
- Close Registry Editor. From now on, any file type of PowerShell script will be opened in PowerShell instead of the Notepad program.