Windows PowerShell Select-Object
Examples of Windows PowerShell Select-Object
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.
Topics for PowerShell Select-Object
Introduction to PowerShell Select-Object
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
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 comparing Select-Object with Format-Table
Conclusion: What can Select-Object do that Format-Table cannot? Let investigate the parameters with Get-Help.
SolarWinds' Network Performance Monitor will help you discover what's happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
To see the full list of parameters call for Get-Help
# PowerShell Select-Object Parameters
Result: Help reveals that Select-Object has parameters which are not be available if you used Format-Table, for example, -first, -last -expand, -skip and -unique.
# PowerShell Select-Object Parameters
Let us try an experiment; we will measure the time it takes to complete the same task but with one difference, filtering with Select-Object or FT (Format-Table).
Experiment A: Format-Table Speed Test
# PowerShell comparing the speed of Format-Table with Select
Result: 75 TotalMilliseconds (fastest of 3 to compensate for caching)
Experiment B: Select-Object Speed Test
# PowerShell Select-Object Speed Test
Result: 28 TotalMilliseconds (fastest of 3 to compensate for caching)
Conclusion: Select-Object is much faster than Format-Table, consequently I only use Format-Table when I need the -Auto feature.
This Engineer's Toolset v10 provides a comprehensive console of 50 utilities for troubleshooting computer problems. Guy says it helps me monitor what's occurring on the network, and each tool teaches me more about how the underlying system operates.
There are so many good gadgets; it's like having free rein of a sweetshop. Thankfully the utilities are displayed logically: monitoring, network discovery, diagnostic, and Cisco tools. Try the SolarWinds Engineer's Toolset now!
Other Uses of Select in PowerShell Cmdlet
There are two other ways 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.
More PowerShell Object Cmdlets
You can use Get-Command to research more of PowerShell's 'Object' family. All you need to do is append the -Noun parameter. Incidentally, you could also try -Verb Select.
If you like this page then please share it with your friends
See more PowerShell examples for syntax
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.