You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enter-PSSession - Clear-Host from non-Windows client to Windows target fails #28115
When targeting a Windows host from a non-Windows host through Enter-PSSession calling Clear-Host fails. The Clear-Host implementation on a Windows target runs the following script:
Calling this in a remote PSSession will send the host method call back to the client which is fine with Windows client but a non-Windows client SetBufferContents for UNIX throws a NotImplementedException. The CursorPosition does still work but the contents are not cleared.
Expected behavior
The console is cleared and the cursor set back to position `0, 0`.
Actual behavior
The cursor position is set back to `0, 0`, `The method or operation is not implemented.` is displayed and original content is not cleared.
Error details
No explicit error for `Get-Error` as the exception isn't sent back to the remote session and just printed on the screen.
> The method or operation is not implemented.
Environment data
All Powershell 7.x versions.
Visuals
The below example shows what happens on a Linux client connecting to Windows.
Screen.Recording.2026-09-28.at.8.58.26.pm.mov
The same error occurs regardless of the transport protocol used.
It would certainly be nice to have and it would align with how Clear-Host works when targeting a non-Windows host but I think at a minimum this should be fixed. Changing the mechanism to VT escape sequences would solve the problem if targeting Windows running the newer version of PowerShell 7.x with that change but when targeting older PowerShell versions, including 5.1, the client will need the fix I have in #28116 to support it. Unless MS is willing to backport the VT sequence change to 5.1 which I doubt would ever happen.
Edit: Also see #28115 (comment) as to why the remote side should not emit the sequences directly.
Ilya (@iSazonov) see #28118 as to why the VT sequences should not actually be emitted by the remote side. The remote should continue to send the PSRemoting specific host call method and the client/local interprets that to send the correct clear VT sequences where it knows more about the terminal being used.
237dmitry that's fine but this issue is specifically around remote PSSessions and even the /usr/bin/clear and Clear-Host on a non-Windows target does not work in an entered PSSession as per #28118. See my point above as to why I think that the PSSession side needs to continue to use the host calls and the local side interprets and clears the console in whatever the local platform specific way is.
/usr/bin/clear and Clear-Host on a non-Windows target does not work in an entered PSSession
Why do not change Clear-Host function on Windows, I think esc-sequences have to work on every host (even on conhost.exe). But I cannot test it (no Windows at all).
And on a Linux host, the pwsh has some limitations. As you wrote before.. For example:
$ [console]::WindowWidth = 100
SetValueInvocationException: Exception setting "WindowWidth": "Operation is not supported on this platform."
237dmitry this specific issue is in relation to Clear-Host and clear when used in a remote PSSession on Windows targets. As I stated in #28118 sending the raw VT sequences from the remote side for the local to interpret is not a good idea because the remote has no idea what terminal the local side is using and whether those VT sequences would work or not.
I'm not saying the local/client side should be avoid these sequences, I'm saying the signal that remote PSSessions use to tell the client should stay this PSRP host method call so that the client and then interpret and use to clear the screen based on the terminfo it has. In fact that is exactly what Console.Clear does on *nix. We just need to ensure that the Console.Clear() call is done on the local side and not remote.
I tested the SSH connection between two Linux systems, and the ESC sequences work without issues. As far as I recall, they work in Windows terminals as well.
Remember this is for Enter-PSSession through PSRemoting and not ssh directly. PSRemoting does not share a tty but goes through a PowerShell specific protocol to exchange input and output. In any case using Console.Clear() will do what you want and is what I called in #28116 to fix this specific issue. The fix was to have the client do the Console.Clear() when it receives the specific PSRemoting host call that clear on the remote side for Windows sends.
Activity
iSazonov commentedon Sep 28, 2026
Since Windows XP/7 is not supported now, maybe a time to switch to VT Esc #21176 (comment)
jborean93 commentedon Sep 28, 2026
It would certainly be nice to have and it would align with how
Clear-Hostworks when targeting a non-Windows host but I think at a minimum this should be fixed. Changing the mechanism to VT escape sequences would solve the problem if targeting Windows running the newer version of PowerShell 7.x with that change but when targeting older PowerShell versions, including 5.1, the client will need the fix I have in #28116 to support it. Unless MS is willing to backport the VT sequence change to 5.1 which I doubt would ever happen.Edit: Also see #28115 (comment) as to why the remote side should not emit the sequences directly.
237dmitry commentedon Sep 28, 2026
Native
/usr/bin/clearoutputs:`e[H`e[2J`e[3J. This is 4 times faster thanClear-Host:Even considering that on Linux this function calls that very
clear:The best result:
jborean93 commentedon Sep 28, 2026
Ilya (@iSazonov) see #28118 as to why the VT sequences should not actually be emitted by the remote side. The remote should continue to send the PSRemoting specific host call method and the client/local interprets that to send the correct
clearVT sequences where it knows more about the terminal being used.237dmitry that's fine but this issue is specifically around remote PSSessions and even the
/usr/bin/clearandClear-Hoston a non-Windows target does not work in an entered PSSession as per #28118. See my point above as to why I think that the PSSession side needs to continue to use the host calls and the local side interprets and clears the console in whatever the local platform specific way is.237dmitry commentedon Sep 28, 2026
Why do not change
Clear-Hostfunction on Windows, I think esc-sequences have to work on every host (even on conhost.exe). But I cannot test it (no Windows at all).And on a Linux host, the
pwshhas some limitations. As you wrote before.. For example:jborean93 commentedon Sep 28, 2026
237dmitry this specific issue is in relation to
Clear-Hostandclearwhen used in a remote PSSession on Windows targets. As I stated in #28118 sending the raw VT sequences from the remote side for the local to interpret is not a good idea because the remote has no idea what terminal the local side is using and whether those VT sequences would work or not.I'm not saying the local/client side should be avoid these sequences, I'm saying the signal that remote PSSessions use to tell the client should stay this PSRP host method call so that the client and then interpret and use to clear the screen based on the terminfo it has. In fact that is exactly what Console.Clear does on *nix. We just need to ensure that the
Console.Clear()call is done on the local side and not remote.237dmitry commentedon Sep 28, 2026
I tested the SSH connection between two Linux systems, and the ESC sequences work without issues. As far as I recall, they work in Windows terminals as well.
jborean93 commentedon Sep 28, 2026
Remember this is for
Enter-PSSessionthrough PSRemoting and notsshdirectly. PSRemoting does not share a tty but goes through a PowerShell specific protocol to exchange input and output. In any case usingConsole.Clear()will do what you want and is what I called in #28116 to fix this specific issue. The fix was to have the client do theConsole.Clear()when it receives the specific PSRemoting host call thatclearon the remote side for Windows sends.237dmitry commentedon Sep 28, 2026
I never managed to get PSRemoting working, not even over SSH. I still haven't figured out how to achieve this.
[console]::Clear()works also fine