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

前端 未结 7 1501
情话喂你
情话喂你 2020-12-02 12:04

I have a problem regarding changing the Execution Policy in my Windows Server 2008+ OS. It is the first time I try to run a script for which I need resource full ac

相关标签:
7条回答
  • 2020-12-02 12:57

    If the PowerShell ExecutionPolicy is being set by a Domain Controller through a group policy, you'll have to reset the ExecutionPolicy to "Bypass" in the registry after every boot. I've created a pair of startup scripts to automate the process. Below, I describe my process.

    Create a folder called %USERPROFILE%\Documents\StartupScripts and then place a PowerShell script called ExecutionPolicy.ps1 in it with following code:

    Push-Location
    Set-Location HKLM:\Software\Policies\Microsoft\Windows\PowerShell
    Set-ItemProperty . ExecutionPolicy "Bypass"
    Pop-Location
    

    Then create a file called %USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\Startup.cmd and place the following code in it:

    PowerShell -Version 3.0 -Command "Set-ExecutionPolicy Unrestricted" >> "%TEMP%\StartupLog.txt" 2>&1
    PowerShell -Version 3.0 "%USERPROFILE%\Documents\StartupScripts\ExecutionPolicy.ps1" >> "%TEMP%\StartupLog.txt" 2>&1
    

    This script will run at the start of every login.

    0 讨论(0)
提交回复
热议问题