【问题标题】:Invoke-Command Powershell "Window Title Cannot be longer than X chacracters"Invoke-Command Powershell“窗口标题不能长于 X 个字符”
【发布时间】:2013-09-06 15:18:00
【问题描述】:

我正在尝试使用 Powershell 远程运行脚本,该脚本仍在运行,但我收到错误 Invoke Command : Window Title cannot be longer than 1023 characters.

这是我的代码:

Invoke-Command -ComputerName Test -FilePath "\\Some\File\Path.ps1"

我意识到在 ISE 中运行该行时会发生什么,它将脚本的 comments in the header 放入文件名中。有没有办法阻止这种行为?我可以使用选项ErrorAction SilentlyContinue 来抑制错误,但它也会抑制所有其他不理想的错误。

【问题讨论】:

    标签: powershell windows-server-2008 powershell-2.0 powershell-3.0 invoke-command


    【解决方案1】:

    如何明确设置窗口标题?这应该避免窗口标题不是您特别想要的。

    $host.UI.RawUI.WindowTitle = 'Windows PowerShell';
    

    【讨论】:

      【解决方案2】:

      此网络链接虽然是 VBS,但确实为您的情况提供了清晰的说明。

      https://blogs.technet.microsoft.com/heyscriptingguy/2005/06/02/how-can-i-display-more-than-1023-characters-in-a-custom-message-box/

      这是一个比您想象的更常见的情况/问题。

      HTH,

      肯特

      【讨论】:

      • 此链接现已损坏。
      • 我能够毫无问题地访问 Technet 链接。
      • 对不起,我没说清楚。此链接不再将您直接带到您所引用的文章。
      • 抱歉 - 我已更正并更新了 TechNet 链接。
      【解决方案3】:

      我知道添加另一个答案可能并不总是令人愉快,但对此有另一种想法..

      您可以制作一个 HTML 文件并显示给用户,而不是向用户显示消息框..

      get-service | ConvertTo-Html -Title "Services" -Body "<H2>The result of get-service</H2> " -Property Name,Status | 
      foreach {if($_ -like "*<td>Running</td>*"){$_ -replace "<tr>", "<tr bgcolor=green>"}elseif($_ -like "*<td>Stopped</td>*"){$_ -replace "<tr>", "<tr bgcolor=red>"}else{$_}} > c:\services.html
      
      get-service | ConvertTo-Html -CssUri "SS64.css" > c:\services.html
      Invoke-Item c:\services.html
      

      参考。 http://ss64.com/ps/convertto-html.html

      【讨论】:

        【解决方案4】:

        在 Azure 中运行 Powershell,我已通过键入“exit”和“enter”来创建新会话来解决问题。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-10-13
          • 2018-02-28
          • 1970-01-01
          • 1970-01-01
          • 2022-12-02
          • 1970-01-01
          • 2018-12-28
          • 1970-01-01
          相关资源
          最近更新 更多