Training
Module
Filter objects out of the pipeline - Training
This module explains how to filter objects out of the pipeline by using the Where-Object cmdlet to specify various criteria.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The LIKE operator determines whether or not a character string matches a specified pattern. The specified pattern can contain exactly the characters to match, or it can contain meta characters. In effect, the LIKE operator matches substrings using the wildcard characters in the following table.
Character | Description |
---|---|
[ ] | Any one character within the specified range ([a-f]) or set ([abcdef]). |
^ | Any one character not within the range ([^a-f]) or set ([^abcdef].) |
% | Any string of 0 (zero) or more characters. The following example finds all instances where "Win" is found anywhere in the class name: SELECT * FROM meta_class WHERE __Class LIKE "%Win%" |
_ (underscore) | Any one character. Any literal underscore used in the query string must be escaped by placing it inside [] (square brackets). |
For example, the following Power shell code retrieves all instances of the Win32_operatingSystem class whose Name property begins with FirstName:
Get-WmiObject win32_computerSystem -filter "Name LIKE 'FirstName%'"
Because the underscore is a meta character, if the query target has an underscore, the "[]" escape characters must surround it. For example, you can query for all the classes that have a double underscore in the name.
To locate all classes with a double underscore in the name, you must escape both underscores with [] (square brackets), for example:
SELECT * FROM meta_class WHERE __CLASS LIKE "%[_][_]%"
You can negate a LIKE statement using NOT; to do so, be sure to place the NOT directly in front of the field name. For example:
Get-WmiObject -computerName "." -query 'Select * FROM Win32_Printer WHERE Local="TRUE" AND Network ="False" AND DriverName LIKE "%HP%" AND NOT PortName LIKE "%10.%" AND NOT PortName LIKE "%\\%"'
Training
Module
Filter objects out of the pipeline - Training
This module explains how to filter objects out of the pipeline by using the Where-Object cmdlet to specify various criteria.
Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!