Your Computer's Facts: `Get-CimInstance`

Get-CimInstance asks Windows' own catalog of facts about the computer, one class at a time, such as Win32_OperatingSystem for the Windows version and the last restart, Win32_LogicalDisk for the disks and Win32_Battery for the battery, and a calculated property turns its bytes into gigabytes.

Journeyman · PowerShell · Operating System · Updated

After this lesson you can

  • Read facts about this PC with Get-CimInstance and a class such as Win32_OperatingSystem, Win32_LogicalDisk or Win32_Battery
  • Turn a disk's Size and FreeSpace into gigabytes and a percent free with calculated properties

Key takeaways

  • Windows keeps a catalog of facts about the computer, called CIM, sorted into classes such as Win32_OperatingSystem, Win32_LogicalDisk and Win32_Battery.
  • Get-CimInstance -ClassName <class> hands back those facts as objects, ready for Select-Object, Where-Object and the rest of the pipeline.
  • The full view can show your name and Windows' serial number, so pick the properties you need before you share the output.
  • Disk sizes come in bytes. A calculated property with / 1GB and [math]::Round turns them into gigabytes and a percent free.

A game you want says it needs Windows 11, 16 GB of memory and 70 GB of free disk space. Or the help desk at work asks, "Which Windows build are you on, and when did the PC last restart?" With the mouse, that's a trip to Settings, then System, then About, then File Explorer for the disks, then the battery icon in the corner: four places, and nothing you can copy into an email in one go. Windows keeps all those facts in one catalog, and one PowerShell command reads it. IT help-desk techs ask it every day, on one PC or on a hundred.

This chapter is Windows only: everything in it reads parts of Windows that a Mac or Linux doesn't have.

Windows' catalog of facts: CIM

Think of a library's card catalog: a drawer for each subject, and in each drawer one card per book. Windows keeps a catalog like that about itself, called CIM (read "sim", from Common Information Model). Each drawer is a class, named after what it describes: Win32_OperatingSystem for Windows itself, Win32_LogicalDisk for the disks, Win32_Battery for the battery. Get-CimInstance (read "get sim instance") opens a drawer and hands back its cards as objects:

Get-CimInstance -ClassName Win32_OperatingSystem
SystemDirectory     Organization BuildNumber RegisteredUser  SerialNumber            Version
---------------     ------------ ----------- --------------  ------------            -------
C:\WINDOWS\system32              26200       sam@example.com 00000-00000-00000-AA000 10.0.26200

Look before you share it: the full view shows the name Windows was registered to and Windows' serial number. Those two are written here as made-up values; yours are your own, and they don't belong in a forum post or a screenshot.

Pick the facts you need

The card has far more on it than that table shows, and Select-Object picks the columns you want, as in Picking Columns: Select-Object:

Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object Caption, Version, BuildNumber, LastBootUpTime
Caption                  Version    BuildNumber LastBootUpTime
-------                  -------    ----------- --------------
Microsoft Windows 11 Pro 10.0.26200 26200       11/3/2026 8:11:05 AM

Caption is the name people use, and BuildNumber is the one support pages ask for. Windows 11 still says 10.0 in its Version: a build number of 22000 or higher is how you tell it's 11. LastBootUpTime is when Windows last started, and it's a date, so subtracting it from now gives how long the PC has been running:

$os = Get-CimInstance -ClassName Win32_OperatingSystem
$uptime = (Get-Date) - $os.LastBootUpTime
"Up for $($uptime.Days) days and $($uptime.Hours) hours"
Up for 6 days and 0 hours

Your dates and numbers are your own PC's. "Have you tried restarting it?" now has an answer you can check.

Disks and memory, in gigabytes

Win32_LogicalDisk has one card per drive. -Filter (read "filter") asks for only the cards you want, here the C: drive. DeviceID='C:' is written in single quotes inside the double quotes:

Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'"
DeviceID DriveType ProviderName VolumeName Size          FreeSpace
-------- --------- ------------ ---------- ----          ---------
C:       3                      OS         1999288397824 865371287552

Size and FreeSpace are in bytes: correct, and hard to read. DriveType 3 means a disk inside the PC (2 is a USB stick, 4 a network drive, 5 a CD or DVD drive), so -Filter "DriveType=3" lists every local disk. The calculated properties from Columns You Make Yourself: Calculated Properties turn the bytes into something a person can read. 1GB (read "one gigabyte") is PowerShell's own number for a gigabyte:

Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'" |
    Select-Object DeviceID,
        @{ Name = 'SizeGB'; Expression = { [math]::Round($_.Size / 1GB, 1) } },
        @{ Name = 'FreeGB'; Expression = { [math]::Round($_.FreeSpace / 1GB, 1) } },
        @{ Name = 'PercentFree'; Expression = { [math]::Round($_.FreeSpace / $_.Size * 100) } }
DeviceID  SizeGB FreeGB PercentFree
--------  ------ ------ -----------
C:       1862.00 805.90       43.00

The table shows two decimal places, as PowerShell 7.6's tables do; the numbers underneath are 1862, 805.9 and 43. A disk under about 15 percent free is one to clean up soon.

Memory lives in a different drawer, Win32_ComputerSystem, as TotalPhysicalMemory, also in bytes:

$pc = Get-CimInstance -ClassName Win32_ComputerSystem
[math]::Round($pc.TotalPhysicalMemory / 1GB, 1)
127.8

The PC these examples ran on is a big desktop; a laptop usually says 8, 16 or 32. Like the operating system's card, the full Win32_ComputerSystem card shows the PC's name and its owner, so pick the one property you need.

The battery, and finding other drawers

Get-CimInstance -ClassName Win32_Battery reads the battery. On a desktop, which has none, it prints nothing at all, and no error: an empty drawer is a normal answer. On a laptop it hands back one card, where EstimatedChargeRemaining is the percent left, such as 87, and BatteryStatus is 2 while it's plugged in.

There are hundreds of drawers. Get-CimClass finds them by name, with * as a wildcard:

Get-CimClass -ClassName Win32_*Battery*
   NameSpace: ROOT/cimv2

CimClassName                        CimClassMethods      CimClassProperties
------------                        ---------------      ------------------
Win32_Battery                       {SetPowerState, Res… {Caption, Description, InstallDate, Name…}
Win32_PortableBattery               {SetPowerState, Res… {Caption, Description, InstallDate, Name…}

Win32_Processor (the CPU) and Win32_PhysicalMemory (each memory stick) are two more worth knowing. Windows PowerShell 5.1 has Get-CimInstance too, and an older command, Get-WmiObject, that tutorials still show; Get-CimInstance works in both, so use it.

Check yourself

2 questions to try on the lesson page.

So what

The facts the help desk asks for are a command away: pick the class, pick the properties, and turn bytes into gigabytes, and you have an answer you can paste into a ticket, without your serial number in it.

Key terms

Cheat sheets

Related