In PowerShell, using write-host $obj writes a textual representation of the object $obj directly to the host's console without putting it into the pipeline.
#
# Pipe an array of strings ...
#
'foo', 'bar', 'baz' |
#
# ... into foreach-object
#
foreach-object {
#
# ... which checks if the
# string is bar ...
#
if ($_ -eq 'bar') {
#
# If it is bar, the object is written
#
write-host $_
}
else {
#
# ... otherwise, it is passed on in
# the pipeline:
#
$_
#
}
}
Seemingly, there is no differences between writing a string using write-host and simply state a string (which passes it on to the next command in the pipeline.
However, if the output of this script is piped into a command, it becomes clear that the string "bar" has «disappeared» from the pipeline:
./vs-string.ps1 | foreach-object {
"I have received the object $_"
}