'How to run powershell cmdlet in cleared screen and restore original upon finish

I am wondering if there is a way, to Stack Powershell's Output Host Temporarily inside a scope.

For example, scenario is to

  • clear the screen when the below function runs
  • restore the original screen when function exits

Demo code:

function Print-InBlank
{
    [CmdletBinding()]
    #Do something like Clear-Host here
    Write-Host "When you see this everything else is gone"
    Write-Host "Type Ctrl-C to restore"
    #Do something like Restore-Host here
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source