# Search for Windows computers in a certain subnet using Active Directory
$subnetQuery='10.10'
$filterString='2016'
$computers=Get-ADComputer -Filter "enabled -eq 'true' -and OperatingSystem -like '*$filterString*'"`
-Properties Name,Operatingsystem,OperatingSystemVersion,IPv4Address |
Sort-Object -Property Operatingsystem | Select-Object -Property Name,Operatingsystem,OperatingSystemVersion,IPv4Address
$results=$computers|?{$_.IPv4Address|?{[string]$_ -like "*$subnetQuery*"}}
write-host "$($results.count) computer(s) have been matched.`r`n$results"
# Sample output
Name            Operatingsystem              OperatingSystemVersion IPv4Address
----            ---------------              ---------------------- -----------
SERVER-NAME-001 Windows Server 2016 Standard 10.0 (14393)           10.10.120.9
SERVER-NAME-002 Windows Server 2016 Standard 10.0 (14393)           10.10.120.10
------ Results truncated ---------