Im trying to write a powershell script to get an OU information for servers which are in nested OU without using QAD cmdlets, i was helped by one stack member to write a code as below
$computerName = "DC1"
$found = $FALSE
$domain = [ADSI]("LDAP://dc=contoso,dc=com")
$ous = ($domain.psbase.children |
Where-Object {$_.psBase.schemaClassName -eq "OrganizationalUnit"} |
Select-Object -expand Name)
foreach ($child in $ous){
$ou = [ADSI]("LDAP://ou=$child,dc=contoso,dc=com")
$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 wanted some help in modifictaion of the same to seacj a computer's existence in a nested OU.
Thanks, Vinith