These are three way that PowerShell uses 'Select':
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
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. In
this case Select is used to choose the columns displayed in the
output.
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 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:
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
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.
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.