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

17,350

Solution 1

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

Solution 2

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
}
Share:
17,350

Related videos on Youtube

IguyKing
Author by

IguyKing

Updated on September 18, 2022

Comments

  • IguyKing
    IguyKing over 1 year

    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?

    • Admin
      Admin almost 5 years
      Actually, "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).
  • IguyKing
    IguyKing almost 7 years
    This just clears the screen. It doesn't reset the terminal settings. reset on linux does more than just clear the screen?