#28118·PowerShell

Enter-PSSession - Clear-Host on non-Windows target fails

Author: jborean93Created Sep 28, 2026Updated Sep 29, 2026
LabelsWG-Interactive-ConsoleWG-RemotingNeeds-Triage

Prerequisites

Steps to reproduce

When connecting to a non-Windows target (Linux, macOS), the clear command resolves to the /usr/bin/clear command and Clear-Host is a thin wrapper around calling /usr/bin/clear and writing those values to the console.

powershell
${function:Clear-Host}

[Console]::Write((
    & (Get-Command -CommandType Application clear | Select-Object -First 1).Definition
))
# .Link
# https://go.microsoft.com/fwlink/?LinkID=2096480
# .ExternalHelp System.Management.Automation.dll-help.xml

This has two problems:

  1. SSH subsystems strip the TERM env var needed for /usr/bin/clear to work
Image
  1. Direct console calls are a no-op due to the console stdout being used for PSRP messages
Image

The only way to get this working is to explicitly set $env:TERM = '...' but this cannot be set generically as it must match up with the TERM you are using locally. You probably can just set it to xterm and it'll match your terminal locally but there's no guarantee that you actually use an xterm compatible terminal. In my case I do and setting it will work.

https://github.com/user-attachments/assets/c085c8a8-a328-46e7-837e-c738fdc882bb

There is a slight side effect in that the console cursor is one line down due to the sequence of processing the new prompt after running a command but that is more cosmetic.

Running Clear-Host rather than clear fails because of the [Console]::Write(clear) doing to /dev/null even with $env:TERM explicitly set.

https://github.com/user-attachments/assets/1d629a40-8119-4153-b818-918659e71b65

What I really think should be happening to fix this is for a remote PSSession on non-Windows to act more like how a Windows target works in that:

  • It defines an alias for clear to point to Clear-Host
  • Has Clear-Host run the following (like on Windows)
  • Both of these only apply when connecting to a PSRemoting endpoint, normal PowerShell sessions keep the existing clear/Clear-Host behaviour
powershell
# ${function:Clear-Host}

$RawUI = $Host.UI.RawUI
$RawUI.CursorPosition = @{X=0;Y=0}
$RawUI.SetBufferContents(
    @{Top = -1; Bottom = -1; Right = -1; Left = -1},
    @{Character = ' '; ForegroundColor = $rawui.ForegroundColor; BackgroundColor = $rawui.BackgroundColor})
# .Link
# https://go.microsoft.com/fwlink/?LinkID=2096480
# .ExternalHelp System.Management.Automation.dll-help.xml

This means the clear operation goes to the actual PSRemoting host call method with known values and this is interpreted locally to call Console.Clear() or /usr/bin/clear if desired. The remote side continues to stay agnostic of the TERM setting and has the local client handle all that as it is better suited to managing the terminal which is actually local.

Please note this is different to https://github.com/PowerShell/PowerShell/issues/28115 which is specifically around connecting to a Windows target from a non-Windows client. This is about connecting to a non-Windows target from any client.

Expected behavior

bash
The console is cleared

Actual behavior

bash
`/usr/bin/clear` outputs `TERM environment not set.` and nothing is cleared.

Error details

bash
No error, the output is from `/usr/bin/term`

Environment data

powershell
Not applicable, present on all PowerShell 7.x versions on non-Windows targets

Visuals

See steps to reproduce.