Posted On January 13, 2022

Search for Windows computers in a certain subnet using Active Directory

kimconnect 0 comments
blog.KimConnect.com >> Codes >> Search for Windows computers in a certain subnet using Active Directory
# 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 ---------

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Python Module: Datetime

Datetime Programs often include dates and time to perform interactive greetings, calculate age, stamping backups,…

PowerShell: Get-NetTCPConnection for Windows 7 & 2008

On Windows 8 & 2012, there's this nifty function named Get-NetTCPConnection that is useful to…

PowerShell: Check Whether an Application Is Installed Using Known Service Name

# Check whether product is installed $serviceName='windows_exporter' function checkUninstall($serviceName){ $cpuArchitecture32bitPointerSize=4 $path=if ([IntPtr]::Size -eq $cpuArchitecture32bitPointerSize) {…