【问题标题】:Double click ps1 file and powershell window disappears双击ps1文件,powershell窗口消失
【发布时间】:2014-09-10 14:30:04
【问题描述】:

我在这里查看过,有一些主题是在谈论要运行的双 clikc ps1 文件。 但我的情况是我有一个 ps1 文件打开这样的远程会话:

$pw = convertto-securestring -AsPlainText -Force -String xxxxxx
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "xxxx\admin",$pw
$pc = Read-Host -Prompt "Please Enter PC name"
$session = new-pssession -computername $pc -credential $cred
Enter-PSSession $session

我试过this way让它双击运行,

powershell.exe -command "& 'C:\A path with spaces\MyScript.ps1' -MyArguments blah"

输入电脑名称后,控制台消失了……

知道为什么吗?

【问题讨论】:

    标签: powershell powershell-2.0 powershell-3.0


    【解决方案1】:

    您是否尝试使用 -NoExit 选项?

    powershell.exe -NoExit -command "& 'C:\A path with spaces\MyScript.ps1' -MyArguments blah"
    

    【讨论】:

    • 谢谢,它适用于 -noexit 选项。不知道有一个 -noexit 选项大声笑
    【解决方案2】:

    此页面提供了一个批处理脚本(和其他信息),使从 Windows 资源管理器启动时具有这种无退出行为(以及路径有空格时的修复)的过程非常容易:http://blog.danskingdom.com/fix-problem-where-windows-powershell-cannot-run-script-whose-path-contains-spaces

    【讨论】:

      猜你喜欢
      • 2020-10-14
      • 1970-01-01
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多