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

Basic CSS: Add Rounded Corners with border-radius

<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css"><style>.red-text {color: red;}h2 {font-family: Lobster, monospace;}p {font-size: 16px;font-family: monospace;}.thick-green-border {border-color: green;border-width: 10px;border-style:…

Import A WMWare.PowerCLI from Behind the Proxy

VMWare PowerCLI is a must for Administrators. Here's a quick script to install it. If…

PowerShell: List Biggest Files and Folders on a Volume

# listBigFilesAndFolders-v0.01.ps1 # Set variables $parentDirectory="C:\" $depth=4 $topX=10 $excludeDirectories="C:\Windows","C:\Program Files","C:\Program Files (x86)" $clusterSizeOfNetworkShare=8192 # Sanitize…