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

How To Automate Youtube Full Screen on Ubuntu Using Python & Selenium

#sudo apt install python3 python3-pip #sudo pip3 install selenium #pip install webdriver-manager # Variables YoutubeUrl="https://www.youtube.com/watch?v=7nT5YawZt-s"…

PowerShell: Function to Execute Function Remotely

Function this function that - this quick snippet is to invoke those func things remotely...…

How to Convert Windows Application to Run as a Service

Pre-requisites: srvany.exe (from rktools) instsrv.exe Copy srvany.exe and instsrv.exe from to c:\windows\system32 >> Run: CMD…