1

I have a ps1 file that is opened by default with Notepad. If I right click this file and choose Run with Powershell, the commands inside the file are correctly run.

But I would like Powershell to be the default program to run (not "open") this file. So, if I just right click the file, then open with, then choose default program and choose Windows Powershell, this is not enough, because the commands are not run. In this way, the file is just "opened", the Powershell windows opens and then disappears after a second.

How could I set Powershell to be the default program to RUN .ps1 files, or at least one particular .ps1 file?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Sean
  • 923
  • 3
  • 14
  • 36

1 Answers1

1

Here are some registry bits to help out.

Double click - runs .ps1

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open]

[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" \"-file\" \"%1\""

Double Click 'Opens' via Notepad.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open]

[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command]
@="\"C:\\Windows\\System32\\notepad.exe\" \"%1\""

This is assuming you are not using any powershell specific IDE (such as powerGUI or Sapien) which are known to alter the default .ps1 action and would require additional settings to make this work.

Knuckle-Dragger
  • 6,644
  • 4
  • 26
  • 41