This web link albeit VBS, does provide clarity and a walk-through for your situation.
This is a more common situation/issue than you would think.
HTH,
Kent
题
I am trying to run a script remotely using Powershell, the script still runs, but I receive an error Invoke Command : Window Title cannot be longer than 1023 characters.
Here is my code:
Invoke-Command -ComputerName Test -FilePath "\\Some\File\Path.ps1"
I realize what is occuring when running the line in ISE, it places the comments in the header
of the script into the files name. Is there a way to prevent this action? I can use the option ErrorAction SilentlyContinue
which suppresses the error, but it also suppresses all other errors which is not ideal.
解决方案 2
This web link albeit VBS, does provide clarity and a walk-through for your situation.
This is a more common situation/issue than you would think.
HTH,
Kent
其他提示
How about setting the Window Title explicitly? That should avoid the window title being anything except what you specifically want.
$host.UI.RawUI.WindowTitle = 'Windows PowerShell';
I know adding another answer may not always be agreeable, but had another thought about this..
Instead of displaying a Message Box to the user, you could craft an HTML file and display to the user..
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
Running Powershell in Azure, I've fixed the problem by typing "exit" and the "enter" to create a new session.