1

How can I change the policy that will allow me to run the PowerShell script on my machine? PowerShell screen

I have tried checking the solution described there:

How do you successfully change execution policy and enable execution of PowerShell scripts

I changed the settings in MMC (Computer Configuration -> Administrative Templates -> Windows Components) and regedit (HKEY_LOCAL_MACHINE -> SOFTWARE -> Policies -> Microsoft -> Windows -> Powershell)

but all the time I am getting that error on the attached screen

Set-ExecutionPolicy : Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope. Due to the override, your shell will retain its current effective execution policy of RemoteSigned. Type "Get-ExecutionPolicy -List" to view your execution policy settings. For more information p p lease see "Get-Help Set-ExecutionPolicy". At line:1 char:46

  • ... -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & 'C ...
  •                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : PermissionDenied: (:) [Set-ExecutionPolicy], SecurityException
    • FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand

How do you successfully change execution policy and enable execution of PowerShell scripts

HKEY_LOCAL_MACHINE -> SOFTWARE -> Policies -> Microsoft -> Windows -> Powershell changed to "ByPass"

Computer Configuration -> Administrative Templates -> Windows Components Turn Script execution: enabled Execution policy: allow all scripts

2 Answers 2

1

Try this and work up.

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

You can try other values for scope.

Get-Help Set-ExecutionPolicy -Parameter scope

Get the values for the enum listed for that parametr:

[Microsoft.PowerShell.ExecutionPolicyScope]::GetValues([Microsoft.PowerShell.ExecutionPolicyScope])
Sign up to request clarification or add additional context in comments.

2 Comments

it worked. But now if I have few PowerShell scripts and I want to create a sequence and run them one by one after they are finished how can I do that? for example I have three scripts one.ps1, two.ps2, three.ps1 and I want a sequence: one.ps1 - wait for the end and then run next, two.ps1 - wait for the end and then run next, three.ps1
Probably depends on what scope worked for you. Generally if you set it in a session, it will apply to that session and children so you can just call the three scripts.
1
  • You've (successfully) updated your script execution policy via a GPO (Group Policy Object; via MMC, as described in your question).

  • GPO-based execution policies have the highest precedence among all the scopes in which you can set a policy; Get-ExecutionPolicy -List shows the scopes in descending order of precedence (among the two GPO scopes, MachinePolicy takes precedence over UserPolicy).

  • Your error message shows an attempt to set the execution policy for the current process (-Scope Process).

  • Because an execution policy in the process scope is overridden by GPO-based execution policies, the process-level attempt is ineffective, and that's what the error message is trying to tell you.

  • You can ignore the error if the GPO-based execution policy is still permissive enough to allow you to run your script, but I suspect that the process-level attempt to set the execution policy stems from running your scripts via File Explorer's context menu, whose invocation command is - unfortunately - defined that way.

    • You can try to modify the invocation command via the registry (HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\shell\0\Command) and remove the Set-ExecutionPolicy call from it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.