Why PowerShell clear screen action is important
The clear screen action gives a clean look to your PowerShell console. Let’s have a look at the terminal’s image shown below. It contains a few commands that are executed successfully and one command displaying an error. You would not be comfortable executing more commands as there is already a mess on the window.
Clearing the console’s screen is recommended for a more enjoyable experience. In the following section, multiple possibilities are considered that would help you to clear the console’s screen.
How to clear the PowerShell screen
As discussed earlier, the PowerShell clear screen action is supported by a function Clear-Host and its two aliases cls and clear. The agenda of this section aims to guide you on clearing the PowerShell screen.
Using Clear-Host function to clear screen in PowerShell
PowerShell automation depends on the Functions, Cmdlets and the Aliases supported by PowerShell. PowerShell’s Clean-Host command clears the screen of your console. The clear-Host function is a standalone operation of PowerShell that cannot be piped or used with any other Cmdlet. Moreover, it does not generate any output (regardless of clearing the screen). The Clear-Host function can be applied in the following way:
Aliases of Clear-Host
The Aliases in PowerShell are associated with functions, cmdlets. However, a user can customize and create aliases for any function/cmdlet in PowerShell. The Clear-Host function supports two built-in aliases Cls and Clear.
You can use Cls alias as shown below:
Moreover, one can clear the PowerShell’s console using Clear alias in the following way.
You would have gone through the ways to clear the screen of PowerShell presented in the above section. It is observed that the PowerShell commands are case insensitive and the same applies to this function as well. So, it is concluded that you can use the Clear-Host and its aliases in any letter case (upper/lower).
PowerShell is a resourceful command-line tool that has cross-platform support for all the operating systems. It has a long list of functions and cmdlets supported by aliases to perform several tasks. In this guide, we have presented the ways to clear the PowerShell screen. By following this guide, you would be able to clear the screen by using either of the three ways provided. The first method exercises the Clear-Host function to get to the clean view of PowerShell’s screen. The other two methods, Cls and Clear also function on the grounds of Clear-Host as they are aliases of Clear-Host.