【问题标题】:Command prompt not executing powershell scripts命令提示符不执行 powershell 脚本
【发布时间】:2018-09-11 02:23:21
【问题描述】:

我今天尝试运行构建,发现我的命令提示符无法执行 powershell 脚本。为了确认这一点,我创建了一个简单地写入控制台的测试 powershell 脚本。该脚本在从 powershell 运行时工作正常,但命令提示符无法识别。截图如下。

test script working from powershell

test script not working from command prompt

关于为什么会发生这种情况的任何建议/解释?

【问题讨论】:

  • PowerShell 不使用当前工作目录作为默认位置来搜索可执行文件。使用powershell -NoProfile -File .\test1.ps1
  • 感谢您的回答。这完美地工作。但是我的 powershell 脚本在没有“-NoProfile”开关参数的情况下之前在命令提示符下运行良好。我不记得对命令提示符设置进行了任何更改
  • 您不必使用-NoProfile。不用-NoProfile 试试。但是,如果您的任何配置文件脚本曾经写入输出,它将出现在您的脚本输出中。不用-File 也可以试试。它会起作用的。但是,这取决于参数在位置 0。
  • 我以powershell .\test1.ps1 的身份执行脚本,没有任何开关参数。这是行不通的。我用-NoProfile试了一下,效果很好。
  • 已解决。我在..\Documents\WindowsPowerShell 文件夹下创建了一个profile.ps1 脚本来加载powershell 的自定义设置。从文件夹中删除 profile.ps1 或添加 -NoProfile 开关参数可以解决此问题。 @lit - 感谢您的意见。帮了大忙!

标签: powershell command-prompt powershell-4.0


【解决方案1】:

解决了。我在..\Documents\WindowsPowerShell 文件夹下创建了一个profile.ps1 脚本来加载powershell 的自定义设置。从文件夹中删除 profile.ps1 或添加 -NoProfile 开关参数可以解决此问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-29
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多