- Courses
- đź’»Programming Languages
- 🪟PowerShell
- PowerShell for System Administration
- Managing Windows Systems
- WMI and CIM
On this page
PowerShell WMI and CIM
Updated on June 19, 2026
By Enrico Hochkoeppler
Web Developer & TutoriaLibre Founder
Windows Management Instrumentation (WMI) and the Common Information Model (CIM) provide a unified, structured way to query and manage almost every aspect of a Windows system. PowerShell integrates deeply with both technologies, but the CIM cmdlets—introduced in PowerShell 3.0—are the modern, recommended approach. They use the WS‑Management protocol (the same as PowerShell Remoting) rather than the older DCOM protocol used by Get-WmiObject, making them more firewall-friendly, reliable, and cross-platform compatible. Get-WmiObject has been deprecated since PowerShell 3.0 and is not available in PowerShell 7 and later. All new scripts should use the CIM cmdlets: Get-CimInstance, Invoke-CimMethod, New-CimSession, and related commands.
Understanding WMI and CIM​
WMI is Microsoft's implementation of the Common Information Model (CIM) , an industry standard maintained by the Distributed Management Task Force (DMTF) for describing system components. CIM defines the structure; WMI provides the Windows-specific implementation.
Conceptually:
- CIM is the standard model.
- WMI is the Windows provider that implements that model.
- PowerShell provides cmdlets that query and manipulate WMI/CIM classes.
Both WMI and CIM expose system information through classes, such as:
Win32_OperatingSystem— operating system detailsWin32_LogicalDisk— disk drive informationWin32_Service— service configuration and stateWin32_Processor— CPU informationWin32_BIOS— BIOS and firmware details
Each class contains properties (data) and methods (actions). For example, Win32_Service includes properties like Name, State, and StartMode, and methods like StartService() and StopService().
WMI vs. CIM in PowerShell​
PowerShell provides two sets of cmdlets for accessing this data.
WMI Cmdlets (Deprecated)​
Get-WmiObjectInvoke-WmiMethodSet-WmiInstance
These use the older DCOM protocol, which requires TCP port 135 and dynamic high ports, often failing across NATs and firewalls. They are not available in PowerShell 7 and later.
CIM Cmdlets (Modern, Recommended)​
Get-CimInstanceInvoke-CimMethodNew-CimSessionGet-CimSessionRemove-CimSessionGet-CimClass
These use WS‑Management (WS‑Man), the same protocol as PowerShell Remoting, which is firewall-friendly and uses a single port (5985 for HTTP, 5986 for HTTPS).
Key Differences​
FeatureGet-WmiObject (Deprecated)Get-CimInstance (Recommended)ProtocolDCOM (port 135 + dynamic ports)WS‑Man (ports 5985/5986)Firewall-friendlyNoYesTab completion for class namesNoYesAvailable in PowerShell 7NoYesCross-platformWindows onlyWorks with any WS‑Man serverSession reuseNoYes, via CIM sessions
For all new scripts and administration tasks, CIM cmdlets are the only correct choice.
Querying System Information with CIM​
CIM classes allow you to retrieve detailed system information in a structured way. The returned objects are native PowerShell objects, so you can pipe them, filter them, and access properties directly.
Retrieving Operating System Information​
Get-CimInstance -ClassName Win32_OperatingSystem
This returns an object containing OS version, build number, system directory, last boot time, and registered user.
To access a specific property directly:
(Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime
Retrieving CPU Information​
Get-CimInstance -ClassName Win32_Processor
This reveals CPU name, number of cores, clock speed, and virtualization support.
Retrieving Disk Information​
Get-CimInstance -ClassName Win32_LogicalDisk
This returns objects for each logical disk, including drive letter, free space, total size, and file system type.
Retrieving BIOS Information​
Get-CimInstance -ClassName Win32_BIOS
This is useful for hardware audits and compliance checks.
Listing Available CIM Classes​
To discover what classes are available on a system:
Get-CimClass -Namespace root\cimv2
Code explanation: Get-CimClass lists all CIM classes in the specified namespace. The root\cimv2 namespace is the default location for most Windows management classes.
Filtering CIM Queries Efficiently​
CIM queries can be filtered at the source using the -Filter parameter, which reduces network overhead and improves performance by retrieving only the data you need.
Filtering by Class Property​
To retrieve only running services:
Get-CimInstance -ClassName Win32_Service -Filter "State='Running'"
Filtering Disks by Drive Type​
DriveType 3 corresponds to local disks (as opposed to network drives or removable media):
Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3"
Using WQL (WMI Query Language)​
For more complex queries, you can use the -Query parameter with WQL:
Get-CimInstance -Query "SELECT * FROM Win32_LogicalDisk WHERE DriveType=3 AND FreeSpace < 1073741824"
Code explanation: This WQL query retrieves local disks with less than 1 GB of free space (1073741824 bytes). WQL allows complex filtering that is not possible with the simple -Filter syntax.
Comparing Filtering Approaches​
ApproachWhen to Use-FilterSimple equality filters on a single property-Query (WQL)Complex filters, multiple conditions, or joining classesWhere-ObjectOnly when filtering cannot be done at the source (least efficient)
Using -Filter or -Query is always more efficient than retrieving all objects and filtering with Where-Object, because the filtering happens on the remote system before data is transmitted.
Managing System Components with CIM Methods​
Many CIM classes expose methods that allow you to perform actions, not just retrieve information.
Stopping a Service Using CIM​
$service = Get-CimInstance -ClassName Win32_Service -Filter "Name='Spooler'"
Invoke-CimMethod -InputObject $service -MethodName StopService
Code explanation: The first command retrieves the service object for the Print Spooler. The second invokes the StopService() method defined by the CIM class. The action is performed on the system through the CIM infrastructure.
Restarting a Service​
$service = Get-CimInstance -ClassName Win32_Service -Filter "Name='Spooler'"
Invoke-CimMethod -InputObject $service -MethodName StopService
Invoke-CimMethod -InputObject $service -MethodName StartService
Creating a Process Remotely​
$params = @{
CommandLine = "notepad.exe"
}
Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments $params
Code explanation: The Win32_Process class has a static Create method. The -Arguments parameter accepts a dictionary of method parameters. This creates a new process on the target system.
CIM Sessions for Remote Management​
CIM sessions allow you to query and manage remote systems using the same syntax as local queries. They are more efficient than creating a new connection for each command.
Creating a CIM Session​
$session = New-CimSession -ComputerName "SERVER01"
Code explanation: New-CimSession creates a client-side object representing a connection to a remote computer. The session contains information about the connection, such as the computer name and the protocol used.
Querying a Remote System​
Get-CimInstance -ClassName Win32_OperatingSystem -CimSession $session
The command runs on the remote machine, but the results are returned to your local session.
Creating Sessions for Multiple Computers​
$servers = "SERVER01", "SERVER02", "SERVER03"
$sessions = New-CimSession -ComputerName $servers
Get-CimInstance -ClassName Win32_OperatingSystem -CimSession $sessions
Code explanation: New-CimSession accepts an array of computer names and returns an array of session objects. Passing the array to -CimSession runs the query on all servers in parallel.
Removing Sessions​
Always clean up sessions when they are no longer needed:
Remove-CimSession $session
CIM Sessions vs. PowerShell Remoting​
Both CIM sessions and PowerShell Remoting use WS‑Man, but they serve different purposes:
FeatureCIM SessionPowerShell RemotingProtocolWS‑ManWS‑ManRemote computer needs PowerShellNoYesUse caseData queries, inventoryFull script executionState persistenceSession persistsSession persistsLightweightYesMore overhead
For inventory and data collection, CIM sessions are the better choice. For complex scripts that require the full PowerShell engine, use PowerShell Remoting.
Practical Administrative Scenarios​
Checking Free Disk Space Across Multiple Servers​
$servers = Get-Content "servers.txt"
foreach ($server in $servers) {
$session = New-CimSession -ComputerName $server
$disks = Get-CimInstance -ClassName Win32_LogicalDisk -CimSession $session -Filter "DriveType=3"
foreach ($disk in $disks) {
[pscustomobject]@{
ComputerName = $server
Drive = $disk.DeviceID
FreeGB = [math]::Round($disk.FreeSpace / 1GB, 2)
TotalGB = [math]::Round($disk.Size / 1GB, 2)
}
}
Remove-CimSession $session
}
Code explanation: This script reads a list of servers from a text file, creates a CIM session to each, queries local disks (DriveType=3), and calculates free space in gigabytes. Each server's results are returned as a custom object.
Collecting Hardware Inventory​
$computer = $env:COMPUTERNAME
$os = Get-CimInstance -ClassName Win32_OperatingSystem
$cpu = Get-CimInstance -ClassName Win32_Processor
$memory = Get-CimInstance -ClassName Win32_PhysicalMemory
$disk = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3"
[pscustomobject]@{
ComputerName = $computer
OSName = $os.Caption
OSVersion = $os.Version
LastBoot = $os.LastBootUpTime
CPUName = $cpu.Name
CPUCores = $cpu.NumberOfCores
TotalMemoryGB = [math]::Round(($memory | Measure-Object -Property Capacity -Sum).Sum / 1GB, 2)
TotalDiskGB = [math]::Round(($disk | Measure-Object -Property Size -Sum).Sum / 1GB, 2)
FreeDiskGB = [math]::Round(($disk | Measure-Object -Property FreeSpace -Sum).Sum / 1GB, 2)
}
Restarting a Remote Service Using CIM​
$session = New-CimSession -ComputerName "SERVER01"
$svc = Get-CimInstance -ClassName Win32_Service -Filter "Name='Spooler'" -CimSession $session
Invoke-CimMethod -InputObject $svc -MethodName StopService
Invoke-CimMethod -InputObject $svc -MethodName StartService
Remove-CimSession $session
Finding Services with a Specific Startup Type​
Get-CimInstance -ClassName Win32_Service -Filter "StartMode='Auto' AND State!='Running'"
Code explanation: This finds services set to start automatically (StartMode='Auto') that are not currently running (State!='Running'). This is useful for identifying services that failed to start during boot.
Using CIM Associations​
CIM supports associations between classes. For example, to find which services depend on a specific service:
Get-CimAssociatedInstance -InputObject (Get-CimInstance -ClassName Win32_Service -Filter "Name='Spooler'") -ResultClassName Win32_DependentService
Code explanation: Get-CimAssociatedInstance finds CIM instances associated with a given instance through an association. The -ResultClassName parameter filters the results to a specific class.
Security Considerations​
Use CIM over WS‑Man (not DCOM). WS‑Man is more secure and firewall-friendly than DCOM, and it supports modern authentication methods.
Always use HTTPS in production. Configure WinRM to use port 5986 with a valid SSL certificate for encrypted communication.
Run with appropriate privileges. Querying certain classes—particularly those in the Security namespace—requires administrative rights. The account must be in the local Administrators group on the remote computer.
Clean up sessions. Always call Remove-CimSession when a session is no longer needed to free resources on both the local and remote systems.
Audit CIM/WMI queries. Enable PowerShell logging and WinRM auditing to track who is querying what information.
Troubleshooting Common Issues​
"Access Denied" Errors​
This typically occurs when:
- The account is not in the local Administrators group on the remote computer
- The WinRM service is not running or not configured
- The firewall is blocking port 5985/5986
"Class Not Found" Errors​
The class name may be incorrect, or the class may be in a different namespace. Use Get-CimClass -Namespace root\cimv2 to list available classes and verify the name.
Timeout Errors​
Large queries or slow networks may cause timeouts. Use -OperationTimeoutSec to increase the timeout:
Get-CimInstance -ClassName Win32_LogicalDisk -OperationTimeoutSec 60
DCOM vs. WS‑Man Protocol Selection​
If you need to use DCOM for compatibility with older systems, you can specify the protocol when creating a CIM session:
$session = New-CimSession -ComputerName "SERVER01" -SessionOption (New-CimSessionOption -Protocol Dcom)
Code explanation: New-CimSessionOption -Protocol Dcom creates a session option object that forces the use of DCOM instead of WS‑Man. This is only necessary for legacy systems that do not support WS‑Man.
Summary​
WMI and CIM provide a powerful, structured, and extensible framework for querying and managing Windows systems. PowerShell integrates deeply with this framework, enabling administrators to:
- Retrieve detailed system and hardware information
- Manage services, processes, and configuration through CIM methods
- Filter queries efficiently at the source using
-Filteror WQL - Perform remote management through CIM sessions
- Build scalable inventory and monitoring solutions
The CIM cmdlets (Get-CimInstance, Invoke-CimMethod, New-CimSession) are the modern, recommended approach and the only option available in PowerShell 7 and later. They use WS‑Management, which is firewall-friendly, supports session reuse, and works across platforms. The older WMI cmdlets (Get-WmiObject) are deprecated and should not be used in new scripts.
By mastering WMI and CIM, you gain access to the deepest layers of Windows system management, far beyond what standard cmdlets expose. This capability is essential for advanced automation, diagnostics, and enterprise-level administration.
Found this helpful? Share the knowledge...
... or support this project to keep it alive!
Previous
Local Users and Groups
Next
Working with APIs and Web Requests
-
Understanding WMI and CIM
-
WMI vs. CIM in PowerShell
- WMI Cmdlets (Deprecated)
- CIM Cmdlets (Modern, Recommended)
- Key Differences
-
Querying System Information with CIM
- Retrieving Operating System Information
- Retrieving CPU Information
- Retrieving Disk Information
- Retrieving BIOS Information
- Listing Available CIM Classes
-
Filtering CIM Queries Efficiently
- Filtering by Class Property
- Filtering Disks by Drive Type
- Using WQL (WMI Query Language)
- Comparing Filtering Approaches
-
Managing System Components with CIM Methods
- Stopping a Service Using CIM
- Restarting a Service
- Creating a Process Remotely
-
CIM Sessions for Remote Management
- Creating a CIM Session
- Querying a Remote System
- Creating Sessions for Multiple Computers
- Removing Sessions
- CIM Sessions vs. PowerShell Remoting
-
Practical Administrative Scenarios
- Checking Free Disk Space Across Multiple Servers
- Collecting Hardware Inventory
- Restarting a Remote Service Using CIM
- Finding Services with a Specific Startup Type
- Using CIM Associations
-
Security Considerations
-
Troubleshooting Common Issues
- "Access Denied" Errors
- "Class Not Found" Errors
- Timeout Errors
- DCOM vs. WS‑Man Protocol Selection
-
Summary
