diff --git a/Write-Host.ps1 b/Write-Host.ps1 index 2698946..8781c9b 100644 --- a/Write-Host.ps1 +++ b/Write-Host.ps1 @@ -57,8 +57,7 @@ function Write-Host { Process { # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_special_characters#escape-e # https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/wmf/whats-new/console-improvements#vt100-support - if ($Host.UI.SupportsVirtualTerminal) { - $Method = if ($NoNewline) { 'Write' } else { 'WriteLine' } + if ($Host.UI.SupportsVirtualTerminal -or $Host.Name -eq "ServerRemoteHost") { $Output = if ($Separator) { $Object -join $Separator } else { "$Object" } # Splitting by regex ensures that this will work on files from Windows/Linux/macOS @@ -71,11 +70,14 @@ function Write-Host { $item = $AnsiTemplate -f $AnsiColor[$ForegroundColor.value__], $item, 39 } - [System.Console]::$Method($item) + if ($Host.Name -eq "ServerRemoteHost") { + if ($NoNewLine) { Microsoft.PowerShell.Utility\Write-Host -NoNewLine $item } else { Microsoft.PowerShell.Utility\Write-Host $item } + } else { + if ($NoNewline) { [System.Console]::Write($item) } else { [System.Console]::WriteLine($item) } + } } - } - else { + } else { Microsoft.PowerShell.Utility\Write-Host @PSBoundParameters } } -} \ No newline at end of file +}