PowerShell's Select-Object is ideal for filtering properties before you
output them to file, printer or even read them on-screen. Perhaps
the underlying command produces too much information, with Select-Object you
can reduce the number of columns passed to the next element, Format-Table
or Out-File.
Let us assume that you want to list the computer's running processes sorted by CPU usage.
The point of piping the output of the 'Sort' phrase into Select-Object is
that you get to choose which properties are displayed.
Incidentally, selecting the properties also means that you get to choose
the order, in this case, I like the name of the process in the first
column.
# PowerShell Select-Object Example Clear-Host Get-Process |
Sort-Object cpu -descending | ` Select-Object
name, cpu, handles, workingset
Note 1: You can shorten Select-Object to plain 'Select', this
is because PowerShell has an alias of that name.
Note 2: For this particular job I prefer to use
Format-Table because I can achieve the same result and in addition
employ -auto to tighten up the columns.
# PowerShell Select-Object Example Clear-Host Get-Process |
Sort-Object cpu -descending | ` Format-Table
name, cpu, handles, workingset -auto
Conclusion: What can Select-Object do that Format-Table
cannot? Let investigate the parameters with Get-Help.
Guy Recommends: Solarwinds' Free Bulk Import Tool
Import users from a spreadsheet. Just provide a list of the
users with their fields in the
top row, and save as .csv file. Then launch this FREE utility and match
your fields with AD's
attributes, click to import the users. Optionally, you can
provide the name of the OU where the new accounts will be born.
There are also two bonus tools in this free download, and all 3 have been approved by Microsoft:
There are three way that PowerShell uses 'Select'.
Perhaps the most common way is to employ Select in a WMI Query Language
(WQL) statement. Such Get-WmiObject examples which use '-query' to
introduce a classic 'Select *' phrase.
The second context for 'Select' in PowerShell is
Select-String. This cmdlet not only opens a file, but also checks for a word, a phrase, or in fact any pattern match.
Another use is Select-Object, which is often abbreviated to plain Select.
If you like this page then please share it with your friends
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.
Windows Management Instrumentation (WMI) is one of the hidden
treasures of Microsoft operating systems.
Fortunately, Solarwinds
have created the
Free WMI Monitor so that you can actually see and understand these gems of
performance information. Take the guess work out of which
WMI counters to use for applications like Microsoft Active Directory,
SQL or Exchange Server.