Don Jones’ Favorite PowerShell Cmdlets, Part 5 of 10: Select-Object
Sometimes PowerShell just gives too much. It’s a very giving shell, after all, but sometimes you just wish it would scale back a bit. And sometimes, it guesses wrong when it tries to read your mind. Two problems, one solution: Select-Object.
For example, sometimes I find that the output of Get-Service isn’t quite what I want. Sometimes I just want a list of service names and whether or not they’re running. Well, Select-Object (or its alias, Select) lets me get just what I want, by specifying the properties that PowerShell lists:
Get-Service | Select Name,Status
Sometimes, when I’m experimenting, I don’t want to have to wait for an entire list of objects to be returned. Select-Object can help with that, too:
Click past the fold for more…
Get-Service | Select -First 10
Combined with Sort-Object, this can be pretty cool:
Get-Process | Sort Handles | Select Name,ID,Handles -Last 10
That’s the top 10 consumers of process handles on your system, conveniently listing just the process’ names, IDs, and their handle usage. Experiment - what can Select-Object do for you?
Don Jones is the Lead Scripting Guru for SAPIEN Technologies and a Windows PowerShell MVP. He’s the co-author of Windows PowerShell: TFM, 2nd Edition and is the Windows PowerShell columnist for TechNet Magazine. Don is also the Director for the new centralized, independent PowerShell online community: www.PowerShellCommunity.org.
Get your hands on the full Don Jones Favorite Cmdlets Series at this address:
http://www.realtime-windowsserver.com/type/mt-search.cgi?tag=don%20jones%20favorite%20cmdlets&blog_id=1

Email This!
Digg it!
Del.icio.us
Reddit!
Newsvine