“How many servers still run 2016? Which ones have less than 8 GB RAM?” Questions like these come up every month. CIM lets you answer them in minutes, from your own desk, for hundreds of servers.
CIM vs WMI
Windows stores system information in WMI classes like Win32_OperatingSystem. The modern way to read them is Get-CimInstance (CIM cmdlets). The old Get-WmiObject still works in Windows PowerShell 5.1 but doesn’t exist in PowerShell 7 – use CIM.
Classes worth knowing
| Class | What you get |
|---|---|
Win32_OperatingSystem |
OS name, version, build, last boot, memory |
Win32_ComputerSystem |
Manufacturer, model, total RAM, domain |
Win32_Processor |
CPU name, cores, logical processors |
Win32_LogicalDisk |
Drives, size, free space |
Win32_NetworkAdapterConfiguration |
IPs, DNS servers, gateway |
Win32_Service |
Services with their logon account |
Win32_BIOS |
Serial number, BIOS version |
Explore any class:
Get-CimInstance Win32_OperatingSystem | Select-Object *
Get-CimClass -ClassName Win32_* | Select-Object -First 30 CimClassName
One server
$os = Get-CimInstance Win32_OperatingSystem
$cs = Get-CimInstance Win32_ComputerSystem
[pscustomobject]@{
Server = $env:COMPUTERNAME
OS = $os.Caption
Build = $os.BuildNumber
RAMGB = [math]::Round($cs.TotalPhysicalMemory / 1GB)
Model = $cs.Model
LastBoot = $os.LastBootUpTime
}
Many servers with CIM sessions
A CIM session reuses one connection for several queries – much faster than connecting for each class:
$servers = Get-Content C:\Temp\servers.txt
$sessions = New-CimSession -ComputerName $servers -ErrorAction SilentlyContinue -ErrorVariable failed
$inventory = foreach ($s in $sessions) {
$os = Get-CimInstance -CimSession $s Win32_OperatingSystem
$cs = Get-CimInstance -CimSession $s Win32_ComputerSystem
$cpu = Get-CimInstance -CimSession $s Win32_Processor
$disk = Get-CimInstance -CimSession $s Win32_LogicalDisk -Filter "DeviceID='C:'"
[pscustomobject]@{
Server = $s.ComputerName
OS = $os.Caption
Build = $os.BuildNumber
Cores = ($cpu | Measure-Object NumberOfCores -Sum).Sum
RAMGB = [math]::Round($cs.TotalPhysicalMemory / 1GB)
CFreeGB = [math]::Round($disk.FreeSpace / 1GB, 1)
Uptime = [math]::Round(((Get-Date) - $os.LastBootUpTime).TotalDays, 1)
}
}
Remove-CimSession $sessions
$inventory | Export-Csv C:\Temp\inventory.csv -NoTypeInformation
$failed | ForEach-Object { "Unreachable: $($_.TargetObject)" }
Installed software (the reliable way)
Avoid Win32_Product – querying it is slow and can trigger MSI repairs on every product. Read the uninstall registry keys instead:
$paths = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
Get-ItemProperty $paths -ErrorAction SilentlyContinue |
Where-Object DisplayName |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Sort-Object DisplayName
Run it across servers with Invoke-Command.
Make it presentable
$style = '<style>body{font-family:Segoe UI;font-size:13px}table{border-collapse:collapse}td,th{border:1px solid #ccc;padding:4px 8px}th{background:#0B1A2E;color:#fff}</style>'
$inventory | Sort-Object OS | ConvertTo-Html -Head $style -Title 'Server inventory' |
Out-File C:\Temp\inventory.html
Then answer questions straight from the data:
$inventory | Group-Object OS | Select-Object Name, Count
$inventory | Where-Object RAMGB -lt 8
FAQ
CIM queries are slow across a WAN – any tips?
Use -Filter (server-side filtering) instead of fetching everything and using Where-Object, select only the properties you need, and run the job close to the servers (e.g. from a jump host or automation agent in that region).
What’s next
Next: Build a module and safe automation patterns.
Practise this topic
Test yourself with free questions on this topic – instant answers and explanations.
Start practice questionsPowerShellCIMWMIInventoryReportingAdvanced