【问题标题】:Problem when running .ps1 script from external program从外部程序运行 .ps1 脚本时出现问题
【发布时间】:2010-11-10 18:56:36
【问题描述】:

我正在尝试使用将调用 Powershell 的外部程序在 Windows Server 2008 上运行简单的 Powershell 脚本(例如,仅使用 dir 命令)

powershell.exe "& 'C:\Temp\myscript.ps1'"

我已设置(以管理员身份运行)执行策略不受限制。毕竟,我从客户端收到此错误

99: File C:\Temp\myscript.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please
 see "get-help about_signing" for more detai  ls.  At line:1 char:2  + & <<<<  'C:\Temp\myscript.ps1'      + CategoryInfo
: NotSpecified: (:) [], PSSecurityException      + FullyQualifiedErrorId : RuntimeException

为什么我会收到此错误?无限制的执行策略还不够吗?

【问题讨论】:

  • 问题已解决:Windows Server 2008 中有两个 Powershell,x64 和 x86。我必须在他们两个中设置不受限制的执行策略。

标签: powershell windows-server-2008


【解决方案1】:

或者

您可以使用 PowerShell.exe 的 -ExecutionPolicy 参数将执行策略设置为仅针对该会话不受限制。这有助于将系统范围的策略保持为默认状态。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-05
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 2015-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多