当使用Write-Host、Write-Output和直接调用对象显示对象时,PowerShell如何处理对象的格式,我有点困惑。
我需要使用Write-Host,因为当我在函数中调用Write-Output时,它会破坏代码。
但是当我使用Write-Host时,显示的数据并不是我所期望的。当我直接调用对象时,我希望看到我的对象(Write-Host也是一样的)。
PS> $files = GetChildItem C:\
PS> $files # Or Write-Output $files
PS> Write-Host $files
PS> Write-Host $files |Format-Table
PS> $files | Format-Table | Write-Host

发布于 2016-04-13 07:20:56
Out-String会将表格式转换为字符串。正如Nick Daniels所指出的那样
$files | Format-Table | Out-String|% {Write-Host $_}https://stackoverflow.com/questions/36585500
复制相似问题