Running Windows Powershell Scripts simply opens it in the editor

Run regedit

HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell

Change the value of the (Default) attribute to 0.

The possible values are following:

  • 0 - execute,
  • Edit - Open in PowerShell ISE,
  • Open - open in Notepad.

For security reasons Microsoft set the default action to Open.


I realized that this question is already answered, but if you really want to run .\filename.ps1, there's a way to do it.

Part 1: Get PowerShell Location

  1. Open Start > All Programs > Accessories > Windows Powershell.
  2. Right click Windows Powershell shortcut.
  3. Left click "Open file location".
  4. Highlight the location bar on the top.
  5. Right click the location bar.
  6. Left click "Copy".

Part 2: Set .ps1 File Association

  1. Go to the location of your .ps1 file.
  2. Right click the .ps1 file.
  3. Left click "Properties".
  4. Find the part where it said "Opens with:". Left click the "Change..." button on its right side.
  5. Left click the "Browse..." button on the bottom right.
  6. Highlight the location bar on the top.
  7. Right click the location bar.
  8. Left click "Paste".
  9. Left click the button with an arrow pointing right on the right side of the location bar.
  10. Left click "powershell.exe".
  11. Left click "Open"
  12. Go back to the "Open with" window.
  13. Left click "OK" on the bottom right.
  14. Go back to the properties window.
  15. Left click "OK" on the bottom right.

Part 3: Run .\filename.ps1 From Command Prompt

  1. Run this from command prompt.

.\filename.ps1

-Y.P.


You can run the Powershell script from the command prompt like this:

powershell -command "& .\filename.ps1"

You may need to change your execution policy to run Powershell scripts.

powershell -command "Set-ExecutionPolicy Unrestricted"

Tags:

Powershell