Screensie
← All guides

Command Line

Advanced WMI Operations with PowerShell CIM

Use WQL filters, associations, and CIM sessions without retrieving unnecessary data.

Updated September 2, 2026Difficulty: AdvancedTime: 7 minApplies to: Windows, Windows 10, Windows 11

Follow the steps in order and stop if the screen or target does not match what is described. Use administrator access only when the task requires it.

Filter at the provider

Use -Filter so the remote provider returns only matching instances.

Command
Get-CimInstance -ClassName Win32_Service -Filter "State='Running' AND StartMode='Auto'" -Property Name, DisplayName, State, StartMode

Request only needed properties

Limiting properties reduces output and accidental disclosure.

Command
Get-CimInstance -ClassName Win32_Process -Property Name, ProcessId, ExecutablePath

Use WQL when appropriate

Complex queries can use -Query.

Command
Get-CimInstance -Query "SELECT DeviceID,Size,FreeSpace FROM Win32_LogicalDisk WHERE DriveType=3"

Reuse one session

Create one CimSession for a short task instead of reconnecting for every query.

Separate reads from changes

Review the complete target set before invoking a CIM method that changes state.

Capture errors

Use -ErrorAction Stop with try/catch and log the target class and computer without recording credentials.