# Execution Policy problem

**URL:** <https://forums.powershell.org/t/execution-policy-problem/5557>\
**Category:** PowerShell Help\
**Created:** [January 18, 2016, 9:55pm UTC](https://forums.powershell.org/t/execution-policy-problem/5557 "2016-01-18T21:55:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![steven-ayers](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@steven-ayers](https://forums.powershell.org/u/steven-ayers)\
**Post date:** [January 18, 2016, 9:55pm UTC](https://forums.powershell.org/t/execution-policy-problem/5557/1 "2016-01-18T21:55:42Z")

</div>

I have a client who is getting the following message even though their Execution Policy is Unrestricted when they try to run a script!

```
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):
```

---

<div class="post-metadata">

**Author:** ![\_timpringle](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/_timpringle/32/276_2.png) [@\_timpringle](https://forums.powershell.org/u/_timpringle)\
**Post date:** [January 19, 2016, 12:58am UTC](https://forums.powershell.org/t/execution-policy-problem/5557/2 "2016-01-19T00:58:26Z")

</div>

Hi Steven,

Run PowerShell both in 64 bit admin mode (via SYSTEM32) and 32 bit admin mode (via SYSWOW64), and set the policy as you want it there. See if that corrects the problem.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [January 19, 2016, 1:13am UTC](https://forums.powershell.org/t/execution-policy-problem/5557/3 "2016-01-19T01:13:51Z")

</div>

Does the script contain a call to Set-ExecutionPolicy? That particular message should only come up when someone runs that cmdlet, just just as a result of running the script.

---

<div class="post-metadata">

**Author:** ![steven-ayers](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@steven-ayers](https://forums.powershell.org/u/steven-ayers)\
**Post date:** [January 19, 2016, 1:38am UTC](https://forums.powershell.org/t/execution-policy-problem/5557/4 "2016-01-19T01:38:23Z")

</div>

It did contain a set-executiopolicy with a force parameter, however when I removed that line of code, it still showed up…

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [January 19, 2016, 1:40am UTC](https://forums.powershell.org/t/execution-policy-problem/5557/5 "2016-01-19T01:40:10Z")

</div>

That is very strange. Try this before running the script:

```
Set-PSBreakpoint -Command Set-ExecutionPolicy
```

Then run it again and see if the breakpoint triggers. If it does, you be able to find exactly where it’s coming from.

---

<div class="post-metadata">

**Author:** ![steven-ayers](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@steven-ayers](https://forums.powershell.org/u/steven-ayers)\
**Post date:** [January 19, 2016, 3:13am UTC](https://forums.powershell.org/t/execution-policy-problem/5557/6 "2016-01-19T03:13:29Z")

</div>

I tried setting both execution policies to unrestricted - no luck.

I added the breakpoint, it never hits it - the Execution Policy change thing pops up. I’m guessing it never hits the script code, rather the Execution Policy change is coming up BECAUSE you’re running a script.

Any ideas guys? Thanks for your help on this!

---

<div class="post-metadata">

**Author:** ![steven-ayers](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@steven-ayers](https://forums.powershell.org/u/steven-ayers)\
**Post date:** [January 19, 2016, 3:18am UTC](https://forums.powershell.org/t/execution-policy-problem/5557/7 "2016-01-19T03:18:03Z")

</div>

It may be worth mentioning, I am using “Run with PowerShell”.

When I run the script from an existing PS window, I don’t have the same issue!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [January 19, 2016, 3:34am UTC](https://forums.powershell.org/t/execution-policy-problem/5557/8 "2016-01-19T03:34:10Z")

</div>

There’s your problem. Here’s what the “Run with PowerShell” command is set to do, in the registry:

```
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'"
```

I suppose I can sort of see the thought process that went into this. They _could_ have just done “powershell.exe -ExecutionPolicy Bypass -File ‘%1’”, but then, if you happened to have set the policy to AllSigned, you’d be ignoring the signature. So instead, they try to only bypass if you’re not set to AllSigned. (Bit odd that this still skips RemoteSigned, though).

They didn’t use -Force on the call to Set-ExecutionPolicy, presumably because they don’t want people running arbitrary scripts by mistake. Remember, ExecutionPolicy is set to ‘Restricted’ by default.

Anyhow, this only affects scripts launched with that particular explorer shortcut. Shouldn’t be a problem in any other circumstance.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:43pm UTC](https://forums.powershell.org/t/execution-policy-problem/5557/9 "2024-05-16T20:43:05Z")

</div>

Closed on May 16, 2024, 8:43pm UTC


