Search within multiple OU's??
when run script below, servers lists in '$ouarray[0]' written names.txt. the $ouarray needs able added to. cannot go parent ou , findall() because there other ou's not want items from. if i'm doing wrong, please point me in right direction. in advance!
$ouarray[0] = [adsi]"ldap://ou=web,ou=dc1,ou=servers,dc=local,dc=domain,dc=com" $ouarray[1] = [adsi]"ldap://ou=mt,ou=dc1,ou=servers,dc=local,dc=domain,dc=com" $ouarray[2] = [adsi]"ldap://ou=web,ou=dc2,ou=servers,dc=local,dc=domain,dc=com" $ouarray[3] = [adsi]"ldap://ou=mt,ou=dc2,ou=servers,dc=local,dc=domain,dc=com" foreach ($ou in $ouarray) { foreach ($child in $ou.psbase.children) { if ($child.objectcategory -like '*computer*') { $strcomputers += $child.name } } } foreach ($strcomputer in $strcomputers) { add-content c:\names.txt -value $strcomputer }
what meant won´t work put objects of type directory entry array, afaik.
can see type of object using $ouarray.gettype()
missunderstood didn´t work completly...
#create array [array]$ouarray = $null #adding "paths" array not complete objects $ouarray += $([adsi]"ldap://ou=web,ou=dc1,ou=servers,dc=local,dc=domain,dc=com").path $ouarray += $([adsi]"ldap://ou=mt,ou=dc1,ou=servers,dc=local,dc=domain,dc=com").path $ouarray += $([adsi]"ldap://ou=web,ou=dc2,ou=servers,dc=local,dc=domain,dc=com").path $ouarray += $([adsi]"ldap://ou=mt,ou=dc2,ou=servers,dc=local,dc=domain,dc=com").path #now in foreach can reassemble again running [adsi]"$oupath" foreach ($oupath in $ouarray) { $ou = [adsi]"$oupath" foreach ($child in $ou.psbase.children) { # controll #$child.name if ($child.objectcategory -like '*computer*') { $strcomputers += $child.name } } } foreach ($strcomputer in $strcomputers) { add-content c:\names.txt -value $strcomputer }
worked on domain far, hope on your´s ;)
Windows Server > Windows PowerShell
Comments
Post a Comment