Powershell:NoNewLine 的替代品?

Powershell: Alternative to NoNewLine?

我有一个脚本在工作,它使用哈希表来存储和比较值,然后将输出写入文本文件。这是我的输出中使用和不使用 NoNewLine 时发生的情况的示例:

使用 NoNewLine:

All servers are all on Version 19.1.5

没有 NoNewLine:

All server are all on 
Version 19.1.5

NoNewLine 解决了这个问题,但我一直在装有 Powershell 5.0 的服务器上对其进行测试。当我在另一台服务器上测试时,Powershell 无法识别 NoNewLine,因为它的版本是 4.0。不幸的是,让所有服务器都使用较新版本的 PS 不是一种选择,那么有没有一种简单的方法可以实现旧 PS 版本可以处理的 NoNewLine 等价物?我已经用谷歌搜索了一段时间,但没有找到任何好的替代品。我尝试做整个 "nr" 事情,但无法让它工作。这是我使用 NoNewLine 的代码:

if (@($TableVersion.Values | Group-Object).Count -eq 1) {
    if (@($TableHash.Values | Group-Object).Count -eq 1) {
        Write-Output "The servers are all on " $TableVersion.Serverapps01 | Out-File D:\Results$Timestamp.txt -NoNewline;
        }
    else {
        Write-Output "The servers are all on " $TableVersion.Serverapps01 " but there are differences in the build files." | Out-File D:\Results$Timestamp.txt -NoNewline;
    }
}
else {
    @(Write-Output "The server versions do not match: "
    $TableVersion.GetEnumerator() | Sort -Property Name | Format-Table -HideTableHeaders) | Out-File D:\Results$Timestamp.txt;
}

只需将一个字符串发送到 Out-File:

Write-Output "The servers are all on $($TableVersion.Serverapps01) but there are differences in the build files." |Out-File D:\Results$Timestamp.txt

您也可以只使用字符串和 -f(格式)运算符:

"The servers are all on {0} but there are differences in the build files." -f $TableVersion.Serverapps01 | Out-File D:\Results$Timestamp.txt

Write-Output 可以但没必要。