I have a Powershell build step that is being executed in a Jenkins build and the console is wrapping the output at column 80 (as appears to be the default). Is there a way to prevent this column wrapping and have Jenkins utilize a more suitable column width for the output we're expecting?
2 Answers
I hit the same issue. I found via this link you can increase the console width and height. I was limited to a maximum of 128 W and 62 H though or I would get errors.
So I ended up with this:
$pshost = get-host
$pswindow = $pshost.ui.rawui
$newsize = $pswindow.buffersize
$newsize.height = 3000
$newsize.width = 128
$pswindow.buffersize = $newsize
$newsize = $pswindow.windowsize
$newsize.height = 62
$newsize.width = 128
$pswindow.windowsize = $newsize
As this width is not enough, when I output an array of objects I pipe it to format-table cmdlet and I use the -Wrap switch.
E.g.
Get-EventLog -LogName Application -Newest 10 | Format-Table -Wrap
Yields the following output:

- 4,286
- 2
- 35
- 42
Although Avner's answer is correct, I found out that the window and buffer size has to be re-defined each time your jenkins pipeline hits a new powershell step.
A way to avoid this, is to set a default window and buffer size for powershell.exe. One way to do it, is explained by mkelement0 in his answer.
Setting
powershell.exe
window-size defaults programmatically:The following PSv5+ snippet sets the default window size for
powershell.exe
-launched console windows to 100 columns by 50 rows.Note that the fact that screen buffer values are inherited from the overall default settings, stored directly in
HKCU:\Console
, adds complexity.
# Determine the target registry key path.
$keyPath = 'HKCU:\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe'
# Get the existing key or create it on demand.
$key = Get-Item $keyPath -ErrorAction SilentlyContinue
if (-not $key) { $key = New-Item $keyPath }
# Determine the new size values.
[uint32] $cols = 100; [uint32] $lines = 50
# Convert to a DWORD for writing to the registry.
[uint32] $dwordWinSize = ($cols + ($lines -shl 16))
# Note: Screen *buffer* values are inherited from
# HKCU:\Console, and if the inherited buffer width is larger
# than the window width, the window width is apparently set to
# the larger size.
# Therefore, we must also set the ScreenBufferSize value, passing through
# its inherited height value while setting its width value to the same
# value as the window width.
[uint32] $dwordScreenBuf = Get-ItemPropertyValue HKCU:\Console ScreenBufferSize -EA SilentlyContinue
if (-not $dwordScreenBuf) { # No buffer size to inherit.
# Height is 3000 lines by default.
# Note that if we didn't set this explicitly, the buffer height would
# default to the same value as the window height.
$dwordScreenBuf = 3000 -shl 16
}
# Set the buffer width (low word) to the same width as the window
# (so that there's no horizontal scrolling).
$dwordScreenBuf = $cols + (($dwordScreenBuf -shr 16) -shl 16)
# Write the new values to the registry.
Set-ItemProperty -Type DWord $key.PSPath WindowSize $dwordWinSize
Set-ItemProperty -Type DWord $key.PSPath ScreenBufferSize $dwordScreenBuf