I have started to experiment with Windows PowerShell (http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx).

I have notice interesting fact. Compare the output format of two commands below.

PS C:\> Get-Process | where {$_.processname -eq "svchost"}

Command above produces nicely formated output in form of the table.

Command below produces output like this, albiet in red color:

PS C:\> Get-Process | where {$_.processname -eq "svchost"} | Write-Host -ForegroundColor red

System.Diagnostics.Process (svchost)

Why is table lost?

Write-Host converts output to the string.

Solution is to use out-string cmdlet. Command below will show formated table in the red color.

PS C:\> Get-Process | where {$_.processname -eq "svchost"} | out-string | Write-Host -ForegroundColor red