Search code examples
powershellpowershell-3.0powergui

Is there a way to have the PowerShell screen clear itself before each command?


I'm playing around with PowerShell and I find myself constantly typing cls before I run commands. Or worse, I run a command, realize that the output from other stuff is making it a pain to navigate, run cls, and rerun my darn command. Is there a way to have the previous command's output cleared before running each command? Obviously it would be ideal if this could be toggled with a command or something simple, but whatever would work. :) Also, I'm playing with PS 3, ISE, and PowerGUI.


Solution

  • Know this is older, but thought I'd pass this along to anyone else looking -

    One trick I use is to simply put "cls" as the first line in my PowerShell editor screen (in my case, using PowerShell ISE). Then each time I run my script, the PowerShell console within the ISE is cleared out, saving time so only my most recent run is shown there.

    I'm not advising to leave "cls" in production scripts - but it is helpful for iterative testing within an ISE where you are constantly checking output in the PowerShell console window based on script input.