How to Clear the Screen in PowerShell

  1. Introduction to PowerShell Clear Screen
  2. Use the Clear-Host Command in PowerShell
  3. Conclusion
How to Clear the Screen in PowerShell

Usually, PowerShell users may experience the messy interface of the console as multiple commands do have various outputs. To get rid of such a situation, we need to clear the screen of the PowerShell console.

This article provides several ways to clear the PowerShell screen scripting environment.

Introduction to PowerShell Clear Screen

The PowerShell clear screen method is supported by the function Clear-Host and its two aliases, cls and clear. The plan of this section aims to guide you on clearing the PowerShell screen.

Clear-Host

Use the Clear-Host Command in PowerShell

PowerShell automation depends on its native functions, cmdlets, and aliases supported by PowerShell. For example, Windows PowerShell’s Clean-Host command clears the screen of your console.

It’s a standalone operation of PowerShell that cannot be piped or used with any other cmdlet. It doesn’t generate output.

We can apply the Clear-Host function in the following way.

Aliases of Clear-Host Command in PowerShell

The aliases in PowerShell are associated with specific native commands. However, we can customize and create aliases for any function or a cmdlet in PowerShell.

For example, the Clear-Host function supports two built-in aliases, cls and clear.

cls

In addition, one can clear the PowerShell’s console using the clear alias in the following way.

clear

We can verify that these aliases use the Clear-Host function through the Get-Alias command.

Example Code:

Get-Alias clear
Get-Alias cls

Output:

PS C:\temp> Get-Alias Clear

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           clear -> Clear-Host

PS C:\temp> Get-Alias Cls

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           cls -> Clear-Host

We would have gone through the ways to clear the screen of PowerShell presented in the above section. However, it is observed that the PowerShell commands are not case sensitive, and the same applies to this function as well.

So, we can conclude that we can use the Clear-Host and its aliases in any letter case (upper or lower).

Conclusion

PowerShell is an innovative command-line tool with cross-platform support for all operating systems. Moreover, the said scripting language has many functions and cmdlets supported by aliases to perform multiple tasks.

In this article, we have presented how to clear the PowerShell screen.

The first method exercises the Clear-Host function to get a cleaner scripting console. The other two ways, Cls and Clear, are also associated with Clear-Host as they are aliases of Clear-Host.

Marion Paul Kenneth Mendoza avatar Marion Paul Kenneth Mendoza avatar

Marion specializes in anything Microsoft-related and always tries to work and apply code in an IT infrastructure.

LinkedIn