A portion of a script I am writing needs to check which OU the computer object is in prior to proceeding. Originally I used DSQUERY with a loop reading the Stdout data (example shown below). But on occassion it will not find the object which i know is there and have tested a manual dsquery query and it worked fine.
I believe i should probably be using the AD.au3 functions but not sure which one to use. What I am trying to accomplish is to get the OU structure the computer object resides in. I then compare it to strings to determine next steps.
Here is the dssquery portion of this script to show what I was using before.
;##### Checks OU #####
$OU_Check = Run(@ComSpec & " /c " & "c:FOLDERdsquery computer -name " & @ComputerName & " -d DOMAIN", @SystemDir, @SW_HIDE, 8)
$loop = "0"
While 1
$loop = Execute($loop + "1")
$OU_Line = StdoutRead($OU_Check)
If StringInStr($OU_Line, @ComputerName) > 0 Then
_Logging("OU Check - OU Found")
ExitLoop
ElseIf $loop = "1000000" Then
_Logging("OU Check - Computer object not found.")
$OU_Line = ""
ExitLoop
EndIf
Wend