# Automate ExecutionPolicy

**URL:** <https://forums.powershell.org/t/automate-executionpolicy/25642>\
**Category:** PowerShell Help\
**Created:** [March 29, 2025, 6:20am UTC](https://forums.powershell.org/t/automate-executionpolicy/25642 "2025-03-29T06:20:00Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![user1010](https://avatars.discourse-cdn.com/v4/letter/u/ba8739/32.png) [@user1010](https://forums.powershell.org/u/user1010)\
**Post date:** [March 29, 2025, 6:20am UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/1 "2025-03-29T06:20:00Z")

</div>

Is it possible to automate ExecutionPolicy setting? Now I have to manually run this before I running scripts - Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine.

Thank you

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [March 29, 2025, 9:38pm UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/2 "2025-03-29T21:38:24Z")

</div>

You can use Group Policy to set an execution policy across your estate.

---

<div class="post-metadata">

**Author:** ![psdarwin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/psdarwin/32/2063_2.png) [@psdarwin](https://forums.powershell.org/u/psdarwin)\
**Post date:** [March 31, 2025, 1:49pm UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/3 "2025-03-31T13:49:57Z")

</div>

For more information on execution policy, including how to set it using group policy:

> **[about\_Execution\_Policies - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.5)**
>
> Describes the PowerShell execution policies and explains how to manage them.

Also, I don’t know how much security is a concern in your organization, but I suggest evaluating if a more restrictive policy than ‘unrestricted’ would allow you to accomplish your goals without opening your systems up to unnecessary risks.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 31, 2025, 5:40pm UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/4 "2025-03-31T17:40:40Z")

</div>

> [@psdarwin](#):
>
> Also, I don’t know how much security is a concern in your organization

The execution policy is not a security feature **!!** ☝😉

> **The execution policy isn’t a security system that restricts user actions**. For example, users can easily bypass a policy by typing the script contents at the command line when they cannot run a script. Instead, the execution policy helps users to set basic rules and prevents them from violating them unintentionally.

---

<div class="post-metadata">

**Author:** ![psdarwin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/psdarwin/32/2063_2.png) [@psdarwin](https://forums.powershell.org/u/psdarwin)\
**Post date:** [March 31, 2025, 6:04pm UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/5 "2025-03-31T18:04:28Z")

</div>

Good point. It is more of an accident prevention measure.

---

<div class="post-metadata">

**Author:** ![user1010](https://avatars.discourse-cdn.com/v4/letter/u/ba8739/32.png) [@user1010](https://forums.powershell.org/u/user1010)\
**Post date:** [April 3, 2025, 11:34pm UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/6 "2025-04-03T23:34:21Z")

</div>

Maybe use RemoteSigned?

**“RemoteSigned”** is one of PowerShell’s execution policies designed to offer a balanced level of security and functionality.

Why does this work with default setting of ExecutionPolicy, lol. 🙂

powershell.exe -ExecutionPolicy Bypass -File

If I ran it from a .bat - I don’t have to set the ExecutionPolicy before.

---

<div class="post-metadata">

**Author:** ![psdarwin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/psdarwin/32/2063_2.png) [@psdarwin](https://forums.powershell.org/u/psdarwin)\
**Post date:** [April 4, 2025, 1:50pm UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/7 "2025-04-04T13:50:32Z")

</div>

Maybe some context would help find answers to your questions.

- What is the default execution policy for your machine? `Get-ExecutionPolicy`
- Are the scripts you are running on the local machine or on the network. This may impact which execution policy will work. Always best to use the most restrictive one that allows the code to run.
- How are you executing your scripts? From PowerShell CLI, Task Scheduler, a shortcut, some other way?
- Is the policy set by Group Policy, or can it be updated? If not by GPO, look at the Scope parameter. Another scope might make the setting stick on your machine instead of just the current session.
- Can you set the execution policy to what you need in your PowerShell profile script, so it always gets set?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 4, 2025, 2:23pm UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/8 "2025-04-04T14:23:04Z")

</div>

> [@psdarwin](#):
>
> Can you set the execution policy to what you need in your PowerShell profile script, so it always gets set?

🤔

Really? 😏

---

<div class="post-metadata">

**Author:** ![psdarwin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/psdarwin/32/2063_2.png) [@psdarwin](https://forums.powershell.org/u/psdarwin)\
**Post date:** [April 4, 2025, 4:18pm UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/9 "2025-04-04T16:18:56Z")

</div>

Yeah, if GPO, that would still get overridden. If not, you probably don’t need to set it more than once. Some days I really should have more coffee before I start trying to answer PowerShell questions 😆

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 4, 2025, 4:46pm UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/10 "2025-04-04T16:46:04Z")

</div>

If the execution policy is set to prevent scripts from running your profile script wouldn’t run … so you couldn’t set the execution policy from inside your profile script. ☝😉

---

<div class="post-metadata">

**Author:** ![psdarwin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/psdarwin/32/2063_2.png) [@psdarwin](https://forums.powershell.org/u/psdarwin)\
**Post date:** [April 4, 2025, 5:53pm UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/11 "2025-04-04T17:53:30Z")

</div>

True, if the default execution policy is set to Restricted or if the script is not signed. Hence my first question - what is the default execution policy.

---

<div class="post-metadata">

**Author:** ![user1010](https://avatars.discourse-cdn.com/v4/letter/u/ba8739/32.png) [@user1010](https://forums.powershell.org/u/user1010)\
**Post date:** [April 5, 2025, 8:25am UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/12 "2025-04-05T08:25:00Z")

</div>

> [@psdarwin](#):
>
> Maybe some context would help find answers to your questions.
> 
> - What is the default execution policy for your machine? `Get-ExecutionPolicy`
> - Are the scripts you are running on the local machine or on the network. This may impact which execution policy will work. Always best to use the most restrictive one that allows the code to run.
> - How are you executing your scripts? From PowerShell CLI, Task Scheduler, a shortcut, some other way?
> - Is the policy set by Group Policy, or can it be updated? If not by GPO, look at the Scope parameter. Another scope might make the setting stick on your machine instead of just the current session.
> - Can you set the execution policy to what you need in your PowerShell profile script, so it always gets set?

_Maybe some context would help find answers to your questions._

_What is the default execution policy for your machine? Get-ExecutionPolicy_

Get-ExecutionPolicy -List;

Scope ExecutionPolicy  
----- ---------------  
MachinePolicy Undefined  
UserPolicy Undefined  
Process Undefined  
CurrentUser Undefined  
LocalMachine Undefined

_Are the scripts you are running on the local machine or on the network._  
Tested locally but will be on a network share, have not tested that yet.

_This may impact which execution policy will work. Always best to use the most restrictive one that allows the code to run._  
_How are you executing your scripts? From PowerShell CLI, Task Scheduler, a shortcut, some other way?_  
Shortcut.

_Is the policy set by Group Policy, or can it be updated? If not by GPO, look at the Scope parameter. Another scope might make the setting stick on your machine instead of just the current session._  
Not at the moment. It would be good if it’s possible to run it anyway. It seems possible with powershell.exe -ExecutionPolicy Bypass -File.

_Can you set the execution policy to what you need in your PowerShell profile script, so it always gets set?_  
You mean in this file? Microsoft.PowerShell\_profile.ps1

It’s possible but if I want to run it on more computers I need to manage to automate that somehow.

---

<div class="post-metadata">

**Author:** ![psdarwin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/psdarwin/32/2063_2.png) [@psdarwin](https://forums.powershell.org/u/psdarwin)\
**Post date:** [April 7, 2025, 11:43am UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/13 "2025-04-07T11:43:18Z")

</div>

It sounds like the command line option you suggest is probably the best way to do this for a shortcut launch. Let us know how it goes.

---

<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:** [May 7, 2025, 11:43am UTC](https://forums.powershell.org/t/automate-executionpolicy/25642/14 "2025-05-07T11:43:47Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
