CIM Integration
PowerShell 5.1 introduced native support for the Common Information Model (CIM), a modern, standardized framework for managing IT infrastructure. While WMI (Windows Management Instrumentation) has been the traditional tool for system management in Windows, CIM provides a more robust, cross-platform, and extensible approach. This section explores how CIM integrates with PowerShell 5.1+, its advantages over WMI, and practical examples of querying CIM data.
Evolution from WMI to CIM¶
CIM is a superset of WMI, built on the DMTF (Distributed Management Task Force) standards. Key differences include:
- Cross-platform support: CIM is designed for use across Windows, Linux, and macOS via PowerShell 7.0+ and DSC (Desired State Configuration).
- Improved performance: CIM queries are faster and more efficient than WMI, especially for large datasets.
- Consistent API: CIM provides a unified interface for querying hardware, software, and configuration data.
- Modern architecture: CIM relies on the CIMOM (Common Information Model Object Manager) instead of the older WMI service.
PowerShell 5.1+ includes the Microsoft.PowerShell.CimAutomation module, enabling direct access to CIM providers without requiring external tools like wbemtest or wmic.
CIM Cmdlets in PowerShell 5.1+¶
PowerShell 5.1+ provides the following CIM cmdlets:
- Get-CimInstance: Queries CIM classes (replaces Get-WmiObject).
- Get-CimClass: Retrieves metadata about CIM classes.
- Get-CimSession: Manages CIM sessions for remote queries.
- Invoke-CimMethod: Executes CIM methods (e.g., rebooting a system).
Example: Querying System Information¶
# Get basic system info using CIM
Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Name, Manufacturer, Model
Example: Listing Available CIM Classes¶
# List all CIM classes in the root/cimv2 namespace
Get-CimClass -Namespace root/cimv2 | Select-Object Name, Caption
Example: Filtering Results¶
# Find all running processes with "chrome" in the name
Get-CimInstance -ClassName Win32_Process | Where-Object { $_.Name -like "*chrome*" } | Select-Object ProcessId, Name
Querying CIM Classes and Properties¶
CIM classes are organized into namespaces (e.g., root/cimv2). To query specific properties:
1. Use Get-CimInstance with the -ClassName parameter.
2. Use Select-Object to format output.
Example: Customizing Output¶
# Get disk drive information with specific properties
Get-CimInstance -ClassName Win32_DiskDrive | Select-Object Model, Size, MediaType
Example: Using CIM Methods¶
# Reboot the local machine using a CIM method
Invoke-CimMethod -ClassName Win32_OperatingSystem -MethodName Reboot
Troubleshooting CIM Queries¶
Common issues include:
- CIM service not running: Ensure the CIM Service (WmiPrvSE) is active:
- Namespace errors: Specify the correct namespace with the
-Namespace parameter:Key takeaways¶
- CIM is the modern successor to WMI, offering cross-platform, efficient, and standardized management capabilities.
- PowerShell 5.1+ includes native CIM cmdlets like
Get-CimInstanceandInvoke-CimMethodfor querying and managing systems. - Always verify the CIM service status and use
-Namespaceto target the correct CIM repository. - Use
Select-Objectto customize output andWhere-Objectto filter results effectively. - For advanced scenarios, combine CIM with DSC or PowerShell 7.0+ for full cross-platform support.