Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running powershell script from explorer = execution policy error

Tags:

powershell

  1. In windows 7 final I've done: Set-ExecutionPolicy unrestricted
  2. In windows explorer, I select a script.ps1 file, select open with, put in c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe
  3. A powershell window flashes briefly with an error about execution policy.

Scripts run fine from within powershell. How can I run them from windows explorer?

like image 584
Ian Kelling Avatar asked Feb 28 '23 06:02

Ian Kelling


2 Answers

Are you sure it's an execution policy error? If it's PowerShell v2, try including the -File parameter before the file name:

"C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" -File "%1"
like image 90
Joey Avatar answered May 10 '23 10:05

Joey


I figured it out. There were clues in "about_Execution_Policies" help item. The process execution policy must have been more restrictive which was overrides the localmachine policy which got set by the standard Set-ExecutionPolicy command.

Group policy overrides all this. You get a template to set that from microsoft, ignore the part of the page that says this applies only to win xp, thats wrong. That page and above help file have the rest of the needed instructions.

like image 23
Ian Kelling Avatar answered May 10 '23 09:05

Ian Kelling