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
- Open SQL Server Management Studio and connect to the site database.
- Paste the query into a new query window.
- Change
@Subnetto the subnet ID you want. - 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
More SCCM SQL queries
Check BitLocker protection status for each computer
Count Configuration Manager client versions in your environment
Find computers that have not rebooted in 14 days
Find computers with low free space on the C: drive
Find computers with no hardware inventory in 30 days
Find duplicate computer names and duplicate serial numbers