Getting powershell to scroll horizontally instead of word wrap

Copper Contributor

Is it possible to get powershell to horizontally scroll for long lines of text instead of having them wrap automatically to the next line?


I'm running python, and if you're familiar with python dataframes you can think of it like a speadsheet. I'm having python output many columns, and right now it's wrapping the output to separate lines. Think of having a sheet in excel where for more columns instead of having a horizontal scroll excel wraps it - it's very unreadable.


Right now, I have to redirect my output to a .txt file and then open in notepad, where I can horizontally scroll without word wrap, to see the output in a readable fashion. However, if I could make powershell horizontally scroll instead of wrapping, this would save me a step.


Alternately, if not possible in powershell but possible in plain old command prompt I can run python in the command prompt. However, I'd prefer not to as I can't SSH into remote servers from plain command prompt, and sometimes I need to run python remotely so it would be useful to do it in powershell, thanks.

9 Replies
Do you want to review the output and do nothing else with it? In Windows Terminal, you can resize it to fit your whole screen, but the output will be wrapped to the horizontal length of your monitor.
I do just want to review the output and nothing further, however I can't resize the window wide enough. I'd probably need 5000-7000 pixels of width to view it all without wrapping, that's too much for one or even two screens, hence why I want to see if it's possible to get a horizontal scroll with no wrap.

@sawtooth500 If you use PowerShell ands store something in a variable, you can pipe and wrap it using $variable | Format-Table -Wrap.  If you use Get-Content c:\temp\xyz\123.txt, it should wrap it for you.

 

Example of using -Wrap, first output was without, then I edited the script and then you can see the difference.

 

Harm_Veenstra_0-1715545876858.png

 

@sawtooth500 

 

Hi, Taras.

 

Try the following, where in this example, I've used a buffer width of 256.

 

$host.UI.RawUI.BufferSize = [System.Management.Automation.Host.Size]::new(256, ($host.UI.RawUI.BufferSize.Height));

 

Note: This is only worth using under the default shells. If you try it under Windows Terminal, it creates issues as Windows Terminal suppresses the horizontal scroll bar.

 

Cheers,

Lain

I tried using both Get-Content and $host.UI.RawUI.BufferSize = [System.Management.Automation.Host.Size]::new(256, ($host.UI.RawUI.BufferSize.Height)); neither gave me a horizontal scroll. To clarify, I do NOT want it to wrap, I want it to horizontally scroll instead of wrapping.

@sawtooth500 

 

Are you using the standard shell?

 

I've tested the standard shells for both Windows PowerShell and PowerShell and I do get the horizontal scroll bar as show below.

 

Given you said you wanted a value of 7,000, you might want to try that instead of the 256 value I was using, since if your current width is greater than 256 characters, you wouldn't expect to see a horizontal scroll bar.

 

Windows PowerShell initial screen set to a display width of 120 characters

LainRobertson_0-1715568478232.png

 

Windows PowerShell screen after running the buffer change command (set to 256 characters width) showing horizontal scroll bar

LainRobertson_1-1715568540207.png

 

The PowerShell default shell behaves the same way, so I haven't bothered including the almost-identical screenshots from it.

 

Cheers,

Lain

I'm guessing I must be doing something wrong then...

https://youtu.be/jZk0wmKtn7w

That's a recording of me trying to change the buffer size as you suggested Lain. As you see with some sample content I have there, it's line wrapping. If I extend the window onto my second monitor, the wrapping stops. Let me know what I'm doing wrong, thanks.

@sawtooth500 

 

I haven't watched the video, however, if you're resizing your window after running the command then the application window property shown below will undo the command's changes.

 

You'd need to uncheck this property to avoid the undoing of the programmatic changing of the buffer width.

 

LainRobertson_0-1715574562970.png

 

Note that unchecking this option means the unchecking will persist between sessions, impacting all future windows as they're opened.

 

I guess that leads to perhaps a final point: if you don't need to change the buffer width dynamically, just set the properties above to your liking and walk away, as that'd be job done.

 

However, if you're saying that even after doing this (and this also applies to the programmatic change method) you still don't see the horizontal scroll bar, then I can't help as I'm not seeing that behaviour on my client using the default shells.

 

Cheers,

Lain

@sawtooth500 

 

And don't forget to use your own value instead of what I used (256 characters) in my simple example. Perhaps try something like 2,048 and see how you go.

 

Cheers,

Lain