Forum Discussion
robmo
Jan 13, 2023Brass Contributor
Finding computer names in a hashtable
Hi, I need a script that can find a list of computers from Active Directory stored in a hashtable and return the CanonicalName when there is a match. I know how to get all AD computers from domain c...
robmo
Jan 13, 2023Brass Contributor
Testing with this additional code, I can find out if a computer is in the hashtable but this might not be very efficient:
foreach ($computer in $computers) {
$found = $false
foreach($name in $allADComputers.Name) {
if($computer -eq $name) {
Write-Host "match"
$found = $true
}
}
if(-not($found)) {
Write-Host "$($computer): no match"
}
}
foreach ($computer in $computers) {
$found = $false
foreach($name in $allADComputers.Name) {
if($computer -eq $name) {
Write-Host "match"
$found = $true
}
}
if(-not($found)) {
Write-Host "$($computer): no match"
}
}