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

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?

1

2 Answers

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

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
}

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like