Can some one help me out to find an OU in which the computer account exists using powershell?
Exemple:
$computerName = "HOST-ES01" $found = $FALSE $domain = [ADSI]("LDAP://dc=dicasquefunfa,dc=dqf) $ous = ($domain.psbase.children | Where-Object {$_.psBase.schemaClassName -eq "OrganizationalUnit"} | Select-Object -expand Name) foreach ($child in $ous){ $ou = [ADSI]("LDAP://ou=$child,dicasquefunfa,dc=dq") $computers = ($ou.psbase.children | Where-Object {$_.psBase.schemaClassName -eq "Computer"} | Select-Object -expand Name) foreach ($client in $computers){ if ($client -eq $computerName) { Write-Host "Found $computerName in" $ou.psBase.name $found = $TRUE } } } if (-not $found) {Write-Host "$computerName not found."}
I want to go with a list of machines and see whether there is in the field
example:
Input_Hosts.txt
Output_Host.txt