How can I reset windows powershell/command prompt, like reset in bash?

4

When I use vagrant on Windows I will sometimes find that newlines aren't respected properly. This is typically after doing a vagrant ssh. So text ends up looking like

This machine with the name 'default' was not found 
                                                   configured for this environment.

In bash when this kind of terminal goofup happens I can run reset and it clears and resets the terminal settings. How can I do something similar in Powershell/CMD and not have to kill the window and start a new powershell/cmd session?

IguyKing

Posted 2017-05-23T13:46:06.170

Reputation: 91

1Actually, "reset" does something else (reset the console settings, including codepages etc). Usually you use "reset" when dumping garbage from a binary files renders your console unusable. If you just want to clear the screen, use "clear" (or press Ctrl+L). – Raúl Salinas-Monteagudo – 2019-07-11T12:54:03.953

Answers

3

Use CLS in both the command prompt and PowerShell.

Note: In PowerShell, CLS is technically an alias of the command Clear-Host.

CLS Clear the screen - Windows CMD - SS64

Syntax: CLS

If CLS is redirected to file, console or executed through FOR /F it will print a line feed character (ASCII 10).

Errorlevels:
If the screen is successfully cleared %ERRORLEVEL% = unchanged (this is a bug) If a bad switch is given = 1

 

Clear-Host - PowerShell - SS64 Clear-Host

Clear the screen.

Syntax: Clear-Host

Standard Aliases for Clear-Host: clear, cls

Steven

Posted 2017-05-23T13:46:06.170

Reputation: 24 804

6This just clears the screen. It doesn't reset the terminal settings. reset on linux does more than just clear the screen? – IguyKing – 2017-07-20T20:27:48.307

1

While not a replacement for the Linux reset command, this PowerShell script will update your PowerShell terminal window buffer width to match the window width, which may fix the alignment issues you mentioned.

I use this script to remove the horizontal scroll bar that appears when I resize down the window horizontally.

function reset {
    Set-Buffer-Width-To-Screen-Width
    Clear-Host
}

function Set-Buffer-Width-To-Screen-Width {
    $h = Get-Host
    $ui = $h.UI.RawUI
    $bufferSize = $ui.BufferSize
    $windowSize = $ui.WindowSize
    $bufferSize.Width = $windowSize.Width
    $ui.BufferSize = $bufferSize
}

Doug Richardson

Posted 2017-05-23T13:46:06.170

Reputation: 233