Guy recommends:
A free trial of
WebHelpDesk

Solarwinds Free WebHelpDesk

Install a ticket-based help desk system from SolarWinds. Download your free trial

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 * remoting services
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: Free WMI Monitor for PowerShellSolarwinds Free WMI Monitor for PowerShell

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft's operating systems.  Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try - it's free.

Download your free copy of WMI Monitor

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   • Windows PowerShell   • PowerShell 3.0 Network

Win32_pingstatus   • WMI Win32_NetworkAdapter   • Win32_NetworkAdapterConfig

Disable NIC   • PowerShell -Filter  • PowerShell -Query   • PowerShell Select   • Free WMI Monitor

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.

 

 *


Custom Search

Site Home

Guy Recommends: WMI Monitor for PowershellSolarwinds WMI Monitor

Windows Management Instrumentation (WMI) is most useful for PowerShell scripting.

SolarWinds have produced this Free WMI Monitor to 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

Author: Guy Thomas Copyright © 1999-2016 Computer Performance LTD All rights reserved.

Please report a broken link, or an error to: