PowerShell ships out of the box with a number of cmdlets that are known as
the out cmdlets that let you control data output directly.
These cmdlets use the PowerShell verb out because they send
information out from PowerShell to somewhere else.
You can find these commands by running Get‑Command ‑Verb
out. And on screen here, I've piped that to Select‑Object
just to get the command name.
There are more results than these two,
but I wanted to pause on Out‑Default and Out‑Host briefly.
We pretty much covered these in the previous module when we spoke about
the formatting system in PowerShell, so I'm not going to have dedicated
demo clips in this module to walk through them.
Just to summarize, Out‑Default is automatically
added to the end of every pipeline,
and it decides on how to format and output objects. Out‑Host sends
the output to the PowerShell host for display,
and because it's the default,
you don't have to specify unless you want to use its parameters.
These are the rest of the out cmdlets,
and we'll be spending a couple of minutes with each of these
cmdlets in the remainder of this module.
There's a couple of fundamental concepts with the out cmdlets.
Firstly,
and this is really important, out cmdlets do not format objects. Out
cmdlets know what to do with formatted data, but if an out cmdlet
receives an object that is not formatted,
it will invoke PowerShell's formatting system to format the object,
which is something we covered in the last module. The out cmdlets,
except for Out‑GridView,
are expecting formatted data, either because it has been
formatted by the default views and rules or because you have
specified the formatting in the pipeline.
You can pipe directly to an out cmdlet in the pipeline.
Or alternatively, each out cmdlet does have an input object parameter,
allowing you to specify the data that the out cmdlet needs to work with.
With the exception of Out‑String, the out cmdlets
don't output objects to the pipeline.
When you use an out cmdlet,
you're telling PowerShell that you're done with the object stream and you no
longer want it to be available for further use in the console.
Because out cmdlets don't output objects to the pipeline,
you need to put out cmdlets at the end of the pipeline.
If you try to pipe an out cmdlet to something else,
it's just not going to work as the out cmdlet will not continue to pass the current objects down the pipeline.