Home   tech  

How to bypass execution policy in Windows operating system powershell

In PowerShell, the "Execution Policy" is a security feature that controls the execution of scripts. By default, PowerShell's execution policy is set to "Restricted," which prevents the execution of scripts. If you execute script without bypassing it, you will see below error.

.\cleanup.ps1 : File C:\Users\PC\Downloads\cleanup.ps1 cannot be loaded. The file C:\Users\PC\Downloads\cleanup.ps1 is
not digitally signed. You cannot run this script on the current system. For more information about running scripts and
setting execution policy, see about_Execution_Policies

To execute a PowerShell script bypassing the execution policy, you can change the execution policy for the current session or for the user. Here's how you can do it:

1. Temporary Bypass:

You can temporarily bypass the execution policy for the current PowerShell session. Open a PowerShell window with administrative privileges and use the following command:

Set-ExecutionPolicy Bypass -Scope Process

After running this command, you can execute your PowerShell script without any issues. Keep in mind that this change will only affect the current session and will not change the system-wide execution policy.

2. Change User Execution Policy:

If you want to permanently change the execution policy for your user account, you can use the following command in an elevated PowerShell window:

Set-ExecutionPolicy Bypass -Scope CurrentUser

This will allow you to execute scripts without bypassing the execution policy every time.

3. Remote Signed Execution Policy:

Alternatively, you can set the execution policy to "RemoteSigned," which allows the execution of locally created scripts and requires a digital signature for remote scripts. This provides a balance between security and flexibility.

Set-ExecutionPolicy RemoteSigned

Remember that changing the execution policy comes with security implications, so be cautious when modifying it. It's recommended to revert to a more restrictive policy (like "Restricted" or "RemoteSigned") after you've finished running your script.

Published on: Aug 02, 2023, 04:26 AM  
 

Comments

John
Thanks for clarification

Add your comment