简体   繁体   中英

How to disable “execution Policy Change” powershell message on Slower or very busy CPU machine?

I recently get the powershell message "Execution Policy Changed" message when i execute .ps1 script file

--------------
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  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"):
---------------

This is unacceptable because i set the unrestricted on the CurrectUser.

    ----
    Scope ExecutionPolicy
    ----- ---------------
    MachinePolicy       Undefined
    UserPolicy       Undefined
    Process       Undefined
    CurrentUser    Unrestricted  <<< HERE
    LocalMachine       Undefined
    ----

Any knows what happens???

This only occurs when machine CPU is very high load (more than 80%) and/or powershell is not cached on RAM.

Thanks in advance guys!!!

PS: Here is mi regedit entries for double-click behaviour:

HKEY_CLASSES_ROOT\\Microsoft.PowerShellScript.1\\Shell\\0\\Command =

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


Video of the problem i get here

Try this to observe the behavior over time:

while ($true){ 
    powershell.exe -Command {Get-ExecutionPolicy }
    sleep 5
}

Since execution of scripts might be restricted, you need to paste it in PowerShell manually. My current hypothesis is that on a fresh restart / memory wipe the execution policy changes to Undefined till it is properly loaded again. On way to prevent the popup is to -Force the change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM