Powershell and Objects
PowerShell is .NET based. .NET is object orientated. Therefore PowerShell is object based. One of the first things we learn about PowerShell is that we are working with .NET objects. Just what does that mean?
Look at the list of cmdlets specifically designed to work directly with objects:
Commonly the aliases foreach, group, select, sort and where are used for their respective cmdlets. These are the ones that are used all of the time and everyone is happy with. What about the others? When was the last time you used Tee-Object?
Tee-Object enables you to store output in a file or variable and display to the console (if tee-object terminates pipeline) or pass along the pipeline
Get-Process | Tee-Object -FilePath ptest.txt | Select name, handles
Will get the current processes, save the information in a file and then display the name and handles of the processes. We can then view the contents of the file.
Even more useful is this
Get-Process | Tee-Object -Variable procs | select name, handles
$procs | select name, handles
This time we put the information into a variable. Note we don't use a $ on the variable name.
We can then input $procs to the pipeline for further analysis.
Any time you may need to dig further into some data think about using tee-object in your pipeline. Could save a bit of effort.
Read the complete post at http://richardsiddaway.spaces.live.com/Blog/cns!43CFA46A74CF3E96!1875.entry