Command Line
Advanced WMI Operations with PowerShell CIM
Use WQL filters, associations, and CIM sessions without retrieving unnecessary data.
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, StartModeRequest only needed properties
Limiting properties reduces output and accidental disclosure.
Command
Get-CimInstance -ClassName Win32_Process -Property Name, ProcessId, ExecutablePathUse 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.