Summarize computers by OS
Documentation: Microsoft Learn
Query AD computer operating systems, group matching values, and sort by count to report how many machine accounts use each OS.
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-ADComputer -Filter * -Properties OperatingSystem | Group-Object OperatingSystem | Sort-Object Count -Descending | Select-Object Name,Count- Stage 1Get-ADComputer
-Filter -Properties - Stage 2Group-Object
Positional values or no named parameters - Stage 3Sort-Object
-Descending - Stage 4Select-Object
Positional values or no named parameters
How it works
Get-ADComputer retrieves every machine account with the OperatingSystem attribute requested, Group-Object buckets them by that value, Sort-Object puts the largest population first, and the projection reports each OS string as Name with its Count.
Adapting it
Add -Filter "Enabled -eq $true" to the retrieval so disabled leftovers stop inflating totals that are about to end up in a project plan.
Requirements
ActiveDirectory module.
If the result is unexpected
The operating-system summary has unexpected blank or duplicate categories.
Directory OS attributes may be stale, missing or inconsistent across builds and editions.
- Inspect representative computer records in each category before deciding how to normalize labels.
Validate the result
Category totals reconcile with the queried computer count, including an explicit unknown category.
Keep the check reliable
Retain original OS values alongside normalized reporting labels.