0
0
PowershellHow-ToBeginner · 4 min read

How to Use Get-WmiObject in PowerShell: Syntax and Examples

Use Get-WmiObject in PowerShell to query Windows Management Instrumentation (WMI) classes and retrieve system information. The basic syntax is Get-WmiObject -Class <ClassName>, where you specify the WMI class you want to query, such as Win32_OperatingSystem.
📐

Syntax

The basic syntax of Get-WmiObject includes specifying the WMI class you want to query. You can also filter results using the -Filter parameter or specify a remote computer with -ComputerName.

  • -Class: The WMI class name to query (required).
  • -Filter: A WQL query string to filter results.
  • -ComputerName: The target computer name (default is local).
  • -Namespace: The WMI namespace (default is root\cimv2).
powershell
Get-WmiObject -Class <ClassName> [-Filter <WQLFilter>] [-ComputerName <Name>] [-Namespace <Namespace>]
💻

Example

This example retrieves information about the operating system on the local computer using the Win32_OperatingSystem WMI class. It shows the OS name, version, and manufacturer.

powershell
Get-WmiObject -Class Win32_OperatingSystem | Select-Object Caption, Version, Manufacturer
Output
Caption Version Manufacturer ------- ------- ------------ Microsoft Windows 10 Pro 10.0.19045 Microsoft Corporation
⚠️

Common Pitfalls

Common mistakes include:

  • Using incorrect or misspelled WMI class names.
  • Not specifying the correct namespace if the class is outside root\cimv2.
  • Trying to query remote computers without proper permissions or network access.
  • Using -Filter with incorrect WQL syntax.

Always verify the class name and test queries locally before using remote queries.

powershell
## Wrong: Misspelled class name
Get-WmiObject -Class Win32_OperatingSystem

## Right: Correct class name
Get-WmiObject -Class Win32_OperatingSystem
📊

Quick Reference

Here is a quick reference for common Get-WmiObject parameters:

ParameterDescription
-ClassSpecify the WMI class to query (e.g., Win32_Processor)
-FilterApply a WQL filter to narrow results (e.g., "Name LIKE '%Intel%'")
-ComputerNameTarget remote computer name (default is local)
-NamespaceWMI namespace to query (default is root\cimv2)
-CredentialCredentials for remote connections

Key Takeaways

Use Get-WmiObject with the -Class parameter to query specific WMI classes.
Always verify WMI class names and namespaces before running queries.
Use -Filter to narrow down results with WQL syntax.
Remote queries require proper permissions and network access.
Get-WmiObject is deprecated in PowerShell 7+, consider using Get-CimInstance for newer scripts.