How to Change Execution Policy

Illustration showing how to view and change PowerShell execution policy: open administrator shell, run Get-ExecutionPolicy, then Set-ExecutionPolicy RemoteSigned or Bypass confirm

How to Change Execution Policy

Understanding the Critical Role of Execution Policies in Your System Security

Every system administrator, developer, and IT professional encounters a moment when they need to run a script, only to be met with an error message about execution policies. This seemingly small roadblock can halt productivity, delay critical updates, and create frustration across teams. Understanding how to properly manage execution policies isn't just a technical skill—it's a fundamental aspect of maintaining secure, efficient systems while enabling the flexibility modern workflows demand.

An execution policy is essentially a safety mechanism built into PowerShell and other scripting environments that determines which scripts can run on your system. Think of it as a security checkpoint that evaluates whether a script should be trusted before allowing it to execute. This concept extends beyond simple permission settings; it represents a balance between system security and operational efficiency, protecting your environment from potentially malicious code while allowing legitimate automation to function.

Throughout this comprehensive guide, you'll discover multiple methods for changing execution policies across different platforms and scenarios. We'll explore the various policy levels, understand when and why you should modify them, examine the security implications of each choice, and provide step-by-step instructions for implementing changes safely. Whether you're working with PowerShell on Windows, managing enterprise environments, or troubleshooting script execution issues, you'll gain the knowledge needed to make informed decisions about execution policy management.

The Foundation: What Execution Policies Actually Control

Before diving into the mechanics of changing execution policies, it's essential to understand what these policies actually govern. Execution policies don't function as traditional security boundaries—they're designed as safety nets to prevent accidental script execution rather than to stop determined attackers. This distinction is crucial because it shapes how you should approach policy management in your environment.

The execution policy system operates on a hierarchy, with policies set at different scopes taking precedence in a specific order. The most restrictive policy always wins when multiple scopes are in play. This hierarchical structure allows for granular control, enabling administrators to set organization-wide standards while still permitting exceptions for specific users or machines when necessary.

"The execution policy is not a security system that restricts user actions. It is a configuration that helps prevent users from unknowingly executing scripts."

The Scope Hierarchy Explained

PowerShell execution policies can be set at five distinct scopes, each serving different administrative purposes. Understanding these scopes is fundamental to implementing effective policy management:

  • MachinePolicy – Set by Group Policy for all users on the computer, this scope takes highest precedence and cannot be overridden by individual users
  • UserPolicy – Configured through Group Policy for the current user, affecting all PowerShell sessions for that user account
  • Process – Applied only to the current PowerShell session, this temporary scope disappears when the session ends
  • CurrentUser – Affects only the current user and is stored in the user's registry hive
  • LocalMachine – Applies to all users on the computer and is stored in the local machine registry

The precedence order flows from top to bottom, with MachinePolicy overriding all others. This design allows IT departments to enforce security standards while still providing flexibility where appropriate. When no explicit policy is set, PowerShell defaults to "Restricted" on Windows clients and "RemoteSigned" on Windows servers.

Available Execution Policy Levels and Their Practical Implications

Each execution policy level offers a different balance between security and functionality. Selecting the appropriate level requires understanding your organization's security requirements, the nature of scripts you'll be running, and the technical sophistication of users who will interact with the system.

Policy Level Script Execution Behavior Best Use Case Security Impact
Restricted No scripts allowed; only interactive commands High-security environments with no automation needs Maximum protection but zero automation capability
AllSigned Only scripts signed by trusted publishers Enterprise environments requiring code verification High security with controlled automation
RemoteSigned Local scripts run freely; downloaded scripts must be signed Standard business environments with internal automation Balanced security for most organizations
Unrestricted All scripts run; warns on downloaded scripts Development environments or isolated systems Minimal protection; relies on user judgment
Bypass No warnings or prompts; everything runs Automated systems or embedded applications No protection; use only in controlled scenarios
Undefined Removes current scope setting; inherits from higher scope Resetting policies to organizational defaults Depends on inherited policy
"Choosing RemoteSigned strikes the right balance for most organizations—it protects against accidentally running downloaded malicious scripts while allowing internal automation to function without unnecessary friction."

Understanding the RemoteSigned Policy in Depth

The RemoteSigned policy deserves special attention because it represents the most commonly implemented setting in production environments. This policy allows locally created scripts to run without any signature requirement, while scripts downloaded from the internet must be digitally signed by a trusted publisher. The system determines whether a script is "from the internet" based on the Zone.Identifier alternate data stream that Windows attaches to downloaded files.

This approach acknowledges a practical reality: organizations need to run their own automation scripts regularly, and requiring digital signatures for every internal script would create an administrative burden that outweighs the security benefit. However, scripts obtained from external sources—where the risk of malicious code is significantly higher—require verification through digital signatures.

Step-by-Step Methods for Changing Execution Policies

Modifying execution policies can be accomplished through several methods, each appropriate for different scenarios and administrative contexts. The method you choose depends on whether you're making a temporary change for testing, implementing a permanent modification for a single user, or deploying an organization-wide policy.

🔧 Using PowerShell Commands Directly

The most straightforward approach involves using PowerShell's built-in cmdlets. This method provides immediate results and is ideal for individual machines or user accounts. Before making any changes, you should always check the current execution policy to understand what you're modifying:

Get-ExecutionPolicy -List

This command displays all execution policies across all scopes, giving you a complete picture of the current configuration. The output shows which policies are set and which scopes are undefined, helping you understand the effective policy that's currently in place.

To change the execution policy for the current user, use the following command structure:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

This command sets the RemoteSigned policy for the current user only, requiring no administrator privileges. The change persists across PowerShell sessions and system restarts, making it suitable for permanent modifications to a user's environment.

"Always use the minimal scope necessary when changing execution policies. Setting policies at the CurrentUser scope prevents unnecessary system-wide changes that could affect other users or conflict with organizational policies."

🛡️ Implementing Temporary Policy Changes

When you need to run a script just once or want to test policy changes without making permanent modifications, the Process scope provides the perfect solution. This approach changes the policy only for the current PowerShell session, reverting to the previous setting when you close the window:

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

Alternatively, you can launch PowerShell with a specific execution policy using a command-line parameter:

powershell.exe -ExecutionPolicy Bypass -File "C:\Scripts\YourScript.ps1"

This method is particularly useful for scheduled tasks or automated processes where you want to ensure a specific execution policy without modifying system settings. The policy applies only to that specific PowerShell process and doesn't affect other sessions or persist beyond the script's execution.

💼 Enterprise-Wide Policy Management Through Group Policy

In domain environments, Group Policy provides the most robust method for managing execution policies across multiple machines. This approach ensures consistency, prevents unauthorized changes, and allows centralized administration. Group Policy settings override local settings, providing IT departments with ultimate control over script execution policies.

To configure execution policies through Group Policy, administrators navigate to the following path in the Group Policy Management Console:

Computer Configuration → Policies → Administrative Templates → Windows Components → Windows PowerShell

Within this location, you'll find the "Turn on Script Execution" policy setting. Enabling this policy allows you to select the desired execution policy level and specify whether it applies to all scripts or only to scripts from trusted sources. The policy can be applied to specific organizational units, allowing different policies for different departments or user groups.

Group Policy settings are automatically refreshed on client machines at regular intervals, typically every 90 minutes with a random offset. Changes take effect without requiring manual intervention on each machine, making this method ideal for large-scale deployments.

Registry-Based Configuration for Advanced Scenarios

For situations where PowerShell commands aren't accessible or when you need to script execution policy changes as part of a larger deployment process, direct registry modification provides an alternative approach. This method requires careful attention to detail, as incorrect registry modifications can cause system instability.

Execution policies are stored in the Windows Registry at specific locations depending on the scope. For the LocalMachine scope, the registry path is:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell

For the CurrentUser scope, the path is:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell

Within these keys, the execution policy is stored as a string value named "ExecutionPolicy" with the policy name as its data. You can modify this value using the Registry Editor (regedit.exe) or through PowerShell commands that manipulate the registry:

Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" -Name "ExecutionPolicy" -Value "RemoteSigned"

"Direct registry modification should be reserved for automated deployment scenarios or situations where standard PowerShell cmdlets aren't available. Always document registry changes and test them in a non-production environment first."

Security Considerations and Best Practices

Changing execution policies involves inherent security trade-offs. While more permissive policies enable greater flexibility and automation capabilities, they also increase the potential attack surface. A comprehensive approach to execution policy management considers not just the technical implementation but the broader security context of your environment.

Implementing Defense in Depth

Execution policies should never be your only security control. They work best as part of a layered security strategy that includes multiple protective mechanisms. Consider implementing the following complementary controls:

  • Application whitelisting through Windows Defender Application Control or AppLocker to restrict which applications and scripts can execute
  • Antivirus and anti-malware solutions that scan scripts before execution and monitor for suspicious behavior
  • User access controls that limit who can create, modify, and execute scripts in sensitive directories
  • Audit logging to track script execution and identify potential security incidents
  • Network segmentation to limit the potential impact if a malicious script does execute

This multi-layered approach ensures that even if one security control fails or is bypassed, other mechanisms remain in place to protect your systems. Execution policies serve as a first line of defense, preventing accidental execution of untrusted code, while other controls provide deeper protection against determined threats.

⚠️ Common Pitfalls to Avoid

Many organizations make predictable mistakes when managing execution policies. Being aware of these pitfalls helps you implement policies more effectively:

  • Setting Unrestricted or Bypass globally – These permissive policies eliminate the protective value of execution policies entirely and should be used only in specific, controlled scenarios
  • Ignoring Group Policy precedence – Local changes won't take effect if Group Policy enforces a different setting, leading to confusion and wasted troubleshooting time
  • Failing to document policy decisions – Without documentation, future administrators may not understand why certain policies were chosen, leading to inappropriate changes
  • Not testing in non-production environments – Policy changes can break existing automation, so always test in development or staging environments first
  • Overlooking the security implications – More permissive policies increase risk, so ensure that compensating controls are in place
"The most secure execution policy is worthless if it prevents legitimate work from getting done. Find the balance that protects your environment while enabling productivity."

Troubleshooting Common Execution Policy Issues

Even with proper implementation, execution policy issues arise regularly. Understanding how to diagnose and resolve these problems quickly minimizes disruption to operations. The most common issues stem from misunderstandings about how policies interact or from environmental factors that affect script execution.

Diagnosing Policy Conflicts

When a script fails to execute despite what appears to be an appropriate execution policy, the issue often involves scope precedence or Group Policy overrides. Begin troubleshooting by gathering comprehensive information about the current policy configuration:

Get-ExecutionPolicy -List

This command reveals policies at all scopes, making conflicts immediately visible. If a more restrictive policy appears at the MachinePolicy or UserPolicy scope, it overrides any less restrictive settings at lower scopes. In such cases, you'll need to address the Group Policy configuration rather than attempting to change local settings.

Another common issue involves the Zone.Identifier alternate data stream on downloaded scripts. Even with RemoteSigned or Unrestricted policies, Windows may block scripts that it identifies as coming from the internet. You can check for this block using:

Get-Item -Path "C:\Scripts\YourScript.ps1" -Stream Zone.Identifier

If this stream exists, you can remove it to unblock the script:

Unblock-File -Path "C:\Scripts\YourScript.ps1"

Resolving "Cannot Be Loaded Because Running Scripts Is Disabled" Errors

This error message is perhaps the most frequently encountered execution policy issue. It appears when PowerShell attempts to run a script but the current execution policy prevents it. The resolution depends on your administrative privileges and organizational policies:

For users with local administrative rights on their machines, setting the execution policy at the CurrentUser scope typically resolves the issue without requiring system-wide changes. For users in managed environments where Group Policy enforces strict execution policies, the resolution requires either requesting an exception from IT administrators or working with them to implement an appropriate policy for your needs.

In development environments where you frequently need to test scripts, consider using the Process scope for temporary policy changes. This approach allows script execution for testing without permanently modifying system settings that might conflict with organizational standards.

Platform-Specific Considerations

While execution policies originated in Windows PowerShell, the concept has evolved as PowerShell has expanded to other platforms. Understanding how execution policies work across different environments ensures consistent security postures regardless of the underlying operating system.

PowerShell Core and Cross-Platform Execution Policies

PowerShell Core (PowerShell 6 and later) runs on Windows, Linux, and macOS, but execution policies behave differently on non-Windows platforms. On Linux and macOS, the default execution policy is Unrestricted and cannot be changed through the Set-ExecutionPolicy cmdlet. This difference reflects the underlying security models of these operating systems, which rely on file permissions rather than execution policies for script security.

Platform Default Policy Can Be Changed Primary Security Mechanism
Windows PowerShell Restricted (clients) / RemoteSigned (servers) Yes, through multiple methods Execution policies + file permissions
PowerShell Core on Windows RemoteSigned Yes, same as Windows PowerShell Execution policies + file permissions
PowerShell Core on Linux Unrestricted No, always Unrestricted File permissions + SELinux/AppArmor
PowerShell Core on macOS Unrestricted No, always Unrestricted File permissions + Gatekeeper

When developing cross-platform PowerShell scripts, design your security model around file permissions and user privileges rather than relying on execution policies. This approach ensures consistent behavior across all platforms where your scripts might run.

Automation and Scripting Best Practices

For organizations that rely heavily on PowerShell automation, managing execution policies becomes part of a broader scripting governance strategy. Implementing consistent practices across your automation portfolio ensures reliability, maintainability, and security.

📝 Building Policy-Aware Scripts

Well-designed scripts should handle execution policy issues gracefully rather than failing cryptically. Consider incorporating execution policy checks into your scripts, particularly those intended for distribution across diverse environments:

$currentPolicy = Get-ExecutionPolicy -Scope CurrentUser
if ($currentPolicy -eq 'Restricted') {
    Write-Warning "Execution policy is set to Restricted. This script may not run properly."
    Write-Host "Consider running: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser"
    exit
}

This approach provides clear guidance to users who encounter execution policy barriers, reducing support burden and enabling self-service problem resolution. For scripts that must run regardless of policy settings, you can include instructions for launching them with the appropriate execution policy parameter.

"Scripts should be defensive and informative. When execution policy issues arise, guide users toward appropriate solutions rather than leaving them confused by cryptic error messages."

Implementing Code Signing for Enhanced Security

Organizations using the AllSigned execution policy must implement a code signing infrastructure. This process involves obtaining code signing certificates, establishing procedures for signing scripts, and managing certificate trust across the organization. While this approach requires significant initial investment, it provides the highest level of assurance that scripts haven't been tampered with and originate from trusted sources.

Code signing involves using a digital certificate to create a cryptographic signature that's embedded in the script file. PowerShell validates this signature before executing the script, verifying both the identity of the signer and the integrity of the code. If the script has been modified after signing, the signature becomes invalid and PowerShell refuses to execute it.

To sign a script, you first obtain a code signing certificate from your organization's certificate authority or a commercial provider. Then use the Set-AuthenticodeSignature cmdlet to apply the signature:

$cert = Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert
Set-AuthenticodeSignature -FilePath "C:\Scripts\YourScript.ps1" -Certificate $cert

The signed script includes a signature block at the end of the file containing the digital signature and certificate information. This block must remain intact for the signature to remain valid, so any modifications to the script require re-signing.

Monitoring and Auditing Script Execution

Changing execution policies is only part of a comprehensive security strategy. Organizations should also implement monitoring and auditing to track script execution, identify potential security incidents, and ensure compliance with security policies. PowerShell provides robust logging capabilities that capture detailed information about script execution.

Enabling PowerShell Script Block Logging

Script block logging records the content of all PowerShell commands and scripts that execute on a system. This feature provides visibility into exactly what code runs, even if attackers attempt to obfuscate their activities. Enable script block logging through Group Policy at:

Computer Configuration → Policies → Administrative Templates → Windows Components → Windows PowerShell → Turn on PowerShell Script Block Logging

Once enabled, PowerShell records script blocks to the Windows Event Log, specifically to the "Microsoft-Windows-PowerShell/Operational" log with Event ID 4104. These logs capture the actual script content, making them invaluable for security investigations and compliance auditing.

For organizations with security information and event management (SIEM) systems, forwarding these logs to centralized collection points enables real-time monitoring and alerting on suspicious script execution patterns. This visibility helps detect potential security incidents quickly, even in environments with permissive execution policies.

🔍 Implementing Module and Transcription Logging

In addition to script block logging, PowerShell offers module logging and transcription logging. Module logging records when PowerShell modules are imported and which commands are executed from them. Transcription logging creates a complete record of PowerShell session activity, including both commands and their output.

These logging mechanisms work together to provide comprehensive visibility into PowerShell usage across your environment. When combined with appropriate execution policies, they create a security posture that balances usability with protection, allowing legitimate automation while detecting and preventing malicious activity.

Frequently Asked Questions
What happens if I set different execution policies at different scopes?

PowerShell applies the most restrictive policy from the effective scope hierarchy. Group Policy settings (MachinePolicy and UserPolicy) always take precedence over local settings. If you set RemoteSigned at the CurrentUser scope but Group Policy enforces Restricted at the MachinePolicy scope, the Restricted policy applies. Use Get-ExecutionPolicy -List to see all configured policies and understand which one is actually in effect.

Can execution policies be bypassed, and does that mean they're ineffective?

Yes, execution policies can be bypassed by determined users through various methods, including launching PowerShell with the -ExecutionPolicy Bypass parameter or copying script content and pasting it directly into a PowerShell session. However, this doesn't make them ineffective—they're designed to prevent accidental script execution, not to stop malicious actors. Think of execution policies as safety guards rather than security boundaries, and implement additional security controls like application whitelisting for stronger protection.

Do I need administrator privileges to change execution policies?

It depends on the scope. Changing the execution policy at the CurrentUser scope requires no special privileges—any user can modify their own execution policy. However, changing policies at the LocalMachine scope requires administrator rights. Group Policy settings can only be modified by domain administrators. For most individual users, setting the policy at the CurrentUser scope provides sufficient flexibility for running scripts.

Why does my script still fail to run after changing the execution policy?

Several factors beyond execution policy can prevent script execution. The script file might be blocked due to the Zone.Identifier alternate data stream (use Unblock-File to resolve this). Group Policy might enforce a more restrictive policy that overrides your local changes. The script might have syntax errors or dependencies that aren't met. File permissions might prevent PowerShell from reading the script. Use Get-ExecutionPolicy -List to verify the effective policy, check for alternate data streams, and review the actual error message carefully for clues about the real cause.

Is it safe to set the execution policy to Unrestricted or Bypass?

These permissive policies eliminate execution policy protection and should be used sparingly. Unrestricted allows all scripts to run but warns about downloaded scripts, while Bypass provides no warnings at all. Use these policies only in isolated development environments, for specific automated processes where you control all script sources, or temporarily for troubleshooting. For production systems, RemoteSigned provides a better balance between functionality and security. If you must use permissive policies, implement compensating controls like application whitelisting, enhanced monitoring, and strict access controls.

How do execution policies work with PowerShell Core on Linux or macOS?

PowerShell Core on non-Windows platforms always uses the Unrestricted execution policy and doesn't support changing it. This reflects the different security models of these operating systems, which rely on file system permissions rather than execution policies. On Linux and macOS, script security is managed through file permissions (scripts must have execute permissions), user privileges, and platform-specific security frameworks like SELinux or Gatekeeper. When writing cross-platform scripts, design your security approach around file permissions rather than execution policies.

SPONSORED

Sponsor message — This article is made possible by Dargslan.com, a publisher of practical, no-fluff IT & developer workbooks.

Why Dargslan.com?

If you prefer doing over endless theory, Dargslan’s titles are built for you. Every workbook focuses on skills you can apply the same day—server hardening, Linux one-liners, PowerShell for admins, Python automation, cloud basics, and more.