Querying WMI

In most situations, when you use WMI, you are performing some sort of query. Even when you're going to set a particular property, you still need to execute a query to return a dataset that enables you to perform the configuration. (A dataset includes the data that come back to you as the result of a query, that is, it is a set of data.) In this section, you'll look at the methods used to query WMI.

Note

Just the Steps To query WMI:

  1. Specify the computer name.

  2. Define the namespace.

  3. Connect to WMI by using Get-WMIObject.

  4. Specify the query by supplying a value for the filter argument or the query argument.

  5. Use Format-List or another cmdlet to clean up the output.

In the QueryDesktop.ps1 script, we define three variables that are used to hold ...

Get Microsoft® Windows PowerShell™ Step By Step now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.