Increase console linesize from batch program

by scottbass at 2012-10-02 01:29:56


I’ve got a script that will be executed both from the command line as well as from a scheduler (JAMS). If the script encounters an error, it parses a log file using Select-String, writing that output to the console, which gets captured in the JAMS log file.

These lines are wrapping in the JAMS log, making them hard to read. I found this hit via Google: … 56814.aspx. So, I can use that technique to increase the window size and hopefully the output line length.

I don’t want to mess with the end user’s console window when he/she is running the script interactively. However, JAMS sets its own Host, which would give me a trigger for my script.

(Get-Host).UI.RawUI output when run from my PS console:

[code2=powershell]Name : ConsoleHost
Version : 2.0
InstanceId : 728a71ec-7a03-4449-aab3-52ca178d6ec1
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-AU
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace

ForegroundColor : DarkYellow
BackgroundColor : DarkMagenta
CursorPosition : 0,13
WindowPosition : 0,0
CursorSize : 25
BufferSize : 220,3000
WindowSize : 220,70
MaxWindowSize : 220,80
MaxPhysicalWindowSize : 240,80
KeyAvailable : False
WindowTitle : Administrator: Windows PowerShell[/code2]

Those are nowhere near my screen colors, but the BufferSize and WindowSize are correct.

(Get-Host).UI.RawUI output from a JAMS Job:

[code2=powershell]Name : JAMSHost
Version :
InstanceId : eb590913-a546-43e8-8155-cb2ddf7a9404
UI : System.Management.Automation.Internal.Host.InternalHostUserI
CurrentCulture : en-AU
CurrentUICulture : en-US
PrivateData : MVPSI.JAMS.Host.PowerShell.JAMSHostInfo
IsRunspacePushed :
Runspace :

ForegroundColor : White
BackgroundColor : Black
CursorPosition : 0,0
WindowPosition : 0,0
CursorSize : 1
BufferSize : 80,120
WindowSize : 255,80
MaxWindowSize : 255,80
MaxPhysicalWindowSize : 255,80
KeyAvailable :
WindowTitle ]

What’s throwing me off is the BufferSize and WindowSize certainly look long enough to prevent the line wrapping. For example, if the line length is 255, why do I get this:

[code2=powershell]UI : System.Management.Automation.Internal.Host.InternalHostUserI

Do you think Powershell or JAMS is wrapping these lines?

by JeffH at 2012-10-02 04:42:47
I suspect it is JAMS since I don’t see anything that looks long enough to wrap in a regular PowerShell console. Usually, when using Out-File to write to log files you can use the -Width parameter to prevent this sort of thing. But if you are implying that your script is running in a JAMS PowerShell host, then the wrapping issue is theirs. Not sure if this really helps.
by DanielS at 2012-10-02 06:20:24
The following should work for you in either the job source or your PowerShell profile:

$pshost = get-host
$pswindow = $pshost.ui.rawui
$newsize = $pswindow.buffersize
$newsize.height = 3000
$newsize.width = 150
$pswindow.buffersize = $newsize