我正在尝试运行一个cmd
文件,该文件从cmd.exe
调用PowerShell脚本,但出现以下错误:
Management_Install.ps1
cannot be loaded because the execution of scripts is disabled on this system.
我运行了以下命令:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
当我从PowerShell运行Get-ExecutionPolicy
时,它返回Unrestricted
PS C:\Users\Administrator\> Get-ExecutionPolicy
Unrestricted
C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts> powershell .\Management_Install.ps1 1
WARNING: Running x86 PowerShell...
File
C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts\Management_Install.ps1
cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing
" for more details.At line:1 char:25
.\Management_Install.ps1
<<<< 1
CategoryInfo : NotSpecified: (:) [], PSSecurityException
FullyQualifiedErrorId : RuntimeException
C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts> PAUSE
Press any key to continue . . .
系统是Windows Server 2008R2
我做错了什么
运行PowerShell时,可以通过添加
-ExecutionPolicy Bypass
绕过单个文件的此策略我也有类似的问题,并注意到Windows Server 2012上的默认
cmd
正在运行x64对于Windows 10、Windows 7、Windows 8、Windows Server 2008 R2或Windows Server 2012,以管理员身份运行以下命令:
x86(32位)
打开
C:\Windows\SysWOW64\cmd.exe
运行命令
powershell Set-ExecutionPolicy RemoteSigned
x64(64位)
打开
C:\Windows\system32\cmd.exe
运行命令
powershell Set-ExecutionPolicy RemoteSigned
您可以使用检查模式
echo %PROCESSOR_ARCHITECTURE%
[Environment]::Is64BitProcess
参考文献:
MSDN - Windows PowerShell execution policies
Windows - 32bit vs 64bit directory explanation
如果您使用的是Windows Server 2008R2,那么PowerShell的x64和x86版本都必须设置其执行策略。您是否在两台主机上都设置了执行策略
作为管理员,您可以通过在PowerShell窗口中键入以下内容来设置执行策略:
有关更多信息,请参见Using the Set-ExecutionPolicy Cmdlet
完成后,可以使用以下命令将策略设置回其默认值:
您可能会看到一个错误:
因此,您可能需要像这样运行命令(如注释中所示):
相关问题 更多 >
编程相关推荐