Mat*_*ton 98
它可能是PowerShell的默认安全级别,(IIRC)只会运行签名脚本.
尝试输入:
set-executionpolicy remotesigned
Run Code Online (Sandbox Code Playgroud)
这将告诉PowerShell允许本地(即在本地驱动器上)运行未签名的脚本.
然后再次尝试执行脚本.
Nad*_*_MK 72
你需要运行Set-ExecutionPolicy:
Set-ExecutionPolicy Restricted <-- Will not allow any powershell scripts to run. Only individual commands may be run.
Set-ExecutionPolicy AllSigned <-- Will allow signed powershell scripts to run.
Set-ExecutionPolicy RemoteSigned <-- Allows unsigned local script and signed remote powershell scripts to run.
Set-ExecutionPolicy Unrestricted <-- Will allow unsigned powershell scripts to run. Warns before running downloaded scripts.
Set-ExecutionPolicy Bypass <-- Nothing is blocked and there are no warnings or prompts.
Run Code Online (Sandbox Code Playgroud)
小智 20
使用:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
Run Code Online (Sandbox Code Playgroud)
始终使用以上命令启用在当前会话中执行PowerShell.
Mic*_*ter 15
通过像这样调用PowerShell,我能够绕过这个错误:
powershell -executionpolicy bypass -File .\MYSCRIPT.ps1
Run Code Online (Sandbox Code Playgroud)
也就是说,我添加了-executionpolicy bypass我调用脚本的方式.
这适用于Windows 7 Service Pack 1.我是PowerShell的新手,因此我可能会注意到这一点,我不知道.
[编辑2017-06-26]我继续在其他系统上使用此技术,包括Windows 10和Windows 2012 R2,没有问题.
这是我现在使用的.这使我不会通过点击它意外地运行脚本.当我在调度程序中运行它时,我添加一个参数:"scheduler"并绕过提示符.
这也会在最后暂停窗口,以便我可以看到PowerShell的输出.
if NOT "%1" == "scheduler" (
@echo looks like you started the script by clicking on it.
@echo press space to continue or control C to exit.
pause
)
C:
cd \Scripts
powershell -executionpolicy bypass -File .\rundps.ps1
set psexitcode=%errorlevel%
if NOT "%1" == "scheduler" (
@echo Powershell finished. Press space to exit.
pause
)
exit /b %psexitcode%
Run Code Online (Sandbox Code Playgroud)
小智 5
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
Run Code Online (Sandbox Code Playgroud)
即使出现以下错误,上面的命令也适用于我:
Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.
Run Code Online (Sandbox Code Playgroud)