Windows PowerShell: Clear-Host



Clear-Host

In PowerShell, the Clear-Host cmdlet is used to clear the console window or terminal screen. It clears all the previous outputs and makes the console window empty. This can be useful to start fresh or to clear clutter from previous output on the console.

When you execute the Clear-Host cmdlet, PowerShell will clear the screen and move the cursor to the top left of the console window. This is similar to the effect of typing cls or clear in the terminal or command prompt.

The syntax for Clear-Host cmdlet is as follows:

Clear-Host [-WhatIf] [-Confirm] [<CommonParameters>]

The -WhatIf and -Confirm parameters are optional and used to display what will happen if the cmdlet is executed or to prompt for confirmation before executing the cmdlet.

Here is an example of how to use the Clear-Host cmdlet:

PS C:\> Get-ChildItem C:\Windows | Out-String -Width 120 | Write-Host
PS C:\> Clear-Host


In this example, the 'Get-ChildItem' cmdlet is used to get a list of files and folders in the 'C:\Windows' directory. The 'Out-String' cmdlet is used to format the output as a string with a width of 120 characters, and the 'Write-Host' cmdlet is used to display the output on the console. After the output is displayed, the 'Clear-Host' cmdlet is used to clear the console window.

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Top Post Ad

Below Post Ad