SCCM SQL queries

List computers in an IP subnet

SQL query for the Configuration Manager database that lists every computer in one IP subnet, or counts computers per subnet.

LanguageSQL
What it does to the systemReads only. It changes nothing.

When you plan a boundary, a distribution point or a network change, you need to know which computers sit in a subnet.

The result shows each computer in the subnet you name. A second query in the notes counts the computers in every subnet.

SQL
-- Type the subnet ID, not a computer address. Example: 192.168.10.0
DECLARE @Subnet NVARCHAR(64) = '192.168.10.0';

SELECT
    rs.Name0            AS ComputerName,
    sn.IP_Subnets0      AS Subnet,
    rs.Client0          AS HasClient,
    rs.Client_Version0  AS ClientVersion
FROM v_R_System rs
JOIN v_RA_System_IPSubnets sn
    ON sn.ResourceID = rs.ResourceID
WHERE sn.IP_Subnets0 = @Subnet
ORDER BY rs.Name0;

How to use it

  1. Open SQL Server Management Studio and connect to the site database.
  2. Paste the query into a new query window.
  3. Change @Subnet to the subnet ID you want.
  4. Run the query.

Good to know

  • To count computers per subnet, run SELECT IP_Subnets0, COUNT(DISTINCT ResourceID) AS Computers FROM v_RA_System_IPSubnets GROUP BY IP_Subnets0 ORDER BY Computers DESC.
  • A computer with wired, wireless and VPN adapters has one row per subnet. It can show in more than one subnet.
  • The addresses themselves are in v_RA_System_IPAddresses, column IP_Addresses0. Both views come from discovery data.
IP subnet network v_RA_System_IPSubnets v_R_System
✉

Get new articles in your inbox

SCCM guides, AI tools, automation tips — sent when published. No spam.