Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



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

Example: Choose Properties Returned by Get-Process

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 ToolFree Download of Solarwinds  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:

  1. Bulk-import new users into Active Directory.
  2. Seek and zap unwanted user accounts.
  3. Find inactive computers.

Download your FREE bulk import tool.

Researching Select-Object's Parameters

Select-Object has parameters such as -first, -last -expand, -skip and -unique, which would not be available if you used Format-Table.

# PowerShell Select-Object Parameters
Clear-Host
Get-Process | Sort-Object cpu -descending | `
Select-Object name, cpu, handles, workingset -first 10

To see the full list of parameters call for Get-Help

# PowerShell Select-Object Parameters
Clear-Host
Get-Help Select-Object -full

Other Uses of Select in PowerShell

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

 


See more PowerShell examples for syntax

PowerShell Home  • Syntax  • ISE (GUI)  • Pipeline  • Format-Table  • Select-Object

Compare-Object  • Compare-Object (Registry)  • Group-Object  • Sort-Object  • Foreach

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.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Custom Search

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

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.

Download your free copy of WMI Monitor

 

Home Copyright © 1999-2012 Computer Performance LTD All rights reserved

Please report a broken link, or an error.