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

Introduction to Windows PowerShell Select

These are three way that PowerShell uses 'Select':

  1. Perhaps the most common way is in a WMI Query Language (WQL) statement.  For example, Get-WmiObject uses '-query' to introduce a classic 'Select * from' a phrase, see example 1
  2. 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. 
  3. Another use is Select-Object, which is often abbreviated to plain Select. In this case Select is used to choose the columns displayed in the output.

Example 1 Select Hard Disk Volumes

This WMI example employs the Win32_logicaldisk class to display volumes with DriveType =3.  A value of 3 means local and non-removable.  See how Select * feeds off Get-WmiObject -query.

# PowerShell Select Statement
Clear-Host
Get-WmiObject -query `
"Select * from Win32_logicaldisk where DriveType ='3'" `
| Format-Table -auto

Note 1:

Example 2 Check to See if Windows Remoting is Running

Here is another example of a WMI Query Language (WQL) statement using 'Select'.

# PowerShell Select * from checking for remoting
Clear-Host
Get-WmiObject -query
"Select * from Win32_service where name='WinRM' "

Note 2:  WinRm is the Windows service which is a prerequisite for PowerShell v 2.0's remoting capabilities.

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.

Example 3: Win32_NTLogEvent with Select *

This script filters the event logs for two properties, log = Application and type = Error; furthermore this PowerShell script formats the output into a table.

# Powershell Select Example from Event Logs
Clear-Host
$Logs = Get-WmiObject -query `
"SELECT * FROM Win32_NTLogEvent WHERE (logfile='system') AND (type='error')"
$Logs | Format-Table EventCode, SourceName, Message -auto

Summary of PowerShell Select

This page deals with PowerShell 'Select' as in is in a WMI Query Language (WQL) statement. For instance, Get-WmiObject uses '-query' to introduce a classic 'Select * from' a phrase.

If you like this page then please share it with your friends

 


See More Microsoft PowerShell WMI Examples:

Home   • PowerShell Get-WmiObject   • PowerShell -Query   • PowerShell Select

Win32_pingstatus   • WMI Win32_NetworkAdapter   • Win32_NetworkAdapterConfig

Disable NIC   • PowerShell -Filter   • Windows PowerShell   • PowerShell 3.0 Network

Please email me if you have any example scripts. 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.