Inventory Windows build information
Documentation: Microsoft Learn
One Get-CimInstance call against Win32_OperatingSystem returns a single instance per machine.
The script
Script reader
Inspect before you run
Inspect the script below. It does not run in this browser.
Inspection only — no command has run.
Show reference output
Inspect this example’s structure
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Get-CimInstance Win32_OperatingSystem | Select-Object CSName,Caption,Version,BuildNumber,OSArchitecture,LastBootUpTime- Stage 1Get-CimInstance
Positional values or no named parameters - Stage 2Select-Object
Positional values or no named parameters
How it works
One Get-CimInstance call against Win32_OperatingSystem returns a single instance per machine. Select-Object narrows it to CSName for the host name, Caption for the edition string, Version and BuildNumber for the servicing level, plus OSArchitecture and LastBootUpTime. Because this goes through CIM rather than the retired WMI cmdlets, LastBootUpTime arrives as a real DateTime with no DMTF string to parse.
Adapting it
Add -ComputerName with an array of names to fan the same query across a fleet, and append Export-Csv when the output is destined for a compliance workbook.
If the result is unexpected
The build number here disagrees with what Winver reports, or a comparison against an expected edition string fails even though the text on screen looks identical.
Version and BuildNumber report the base build without the update revision, so a fully patched machine looks the same as an unpatched one at the same build. Caption carries trailing whitespace on several server editions, which quietly breaks equality tests. Neither field is wrong; both mislead a comparison built on them.
- Read UBR from HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion to recover the revision the base build omits.
- Trim Caption before comparing, or match with -like and a wildcard rather than -eq.
- Cross-check with Get-ComputerInfo, which surfaces the fuller version detail in one object.
- Confirm LastBootUpTime arrives as a DateTime, since older WMI code paths return a DMTF-formatted string instead.
- Compare against Get-HotFix output if the underlying question is really about patch state.
Validate the result
BuildNumber combined with UBR matches the version string Winver shows exactly, and the edition comparison now returns true for a machine you know matches.
Keep the check reliable
Compare on build and revision numbers rather than on edition text, and keep the trim inside any function that hands Caption back to a caller.