我写了一个简单的批文件作为PowerShell脚本,而且我越来越错误时,他们运行。

它在一个脚本目录我的道路。

Cannot be loaded because the execution of scripts is disabled on this system. 
please see "get-help about-signing".

我看着帮助,但这是不到帮助。

有帮助吗?

解决方案

这可能是PowerShell是默认的安全水平,(请参考)将只运行签署了脚本。

试试打字:

set-executionpolicy remotesigned

那会告诉PowerShell允许地方(即,在一个地方驱动)未签名的脚本运行。

然后尽量执行你的脚本了。

其他提示

你需要运行 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.

使用:

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

总是利用上述命令,以使执行问题和本届会议。

我能够绕过这个错误援引PowerShell这样的:

powershell -executionpolicy bypass -File .\MYSCRIPT.ps1

这是我加的 -executionpolicy bypass 到了我用脚本。

这一工作窗7Service Pack1。我是新来的PowerShell,因此可能有需要注意到这样做,我不知道。

[编辑2017-06-26]我们继续使用这种技术对其他系统,包括Windows10和Windows2012年R2没有问题。

这里是什么我使用的是现在。这让我意外运行的脚本,通过点击。当我运行了它在安排程序添加一个参数:"计划程序",并绕过提示。

这也暂停窗口的结束,所以我可以看到的输出置。

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%
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

上述命令的工作对我来说甚至在以下错误的情况:

Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.

还值得知道你可能需要包括 .\ 在前面的脚本的名字。例如:

.\scriptname.ps1

该命令 set-executionpolicy unrestricted 将允许任何脚本,你创建运行为的记录用户。只是一定要的executionpolicy设置回签名的使用 set-executionpolicy signed 命令之前登出。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top