Give this script a shot and let me know if works.

Code:

break on
? "Enter username: "
gets $user
$OU = getOU($user)
? $OU

function getOU($userName)
dim $dn,$objRootDSE,$strDomain
dim $objConnection,$objCommand
dim $objRecordSet
$getOU = "Not Found"
$objRootDSE = GetObject("LDAP://RootDSE")
$strDomain = $objRootDSE.Get("DefaultNamingContext")

$objConnection = CreateObject("ADODB.Connection")
$objConnection.Open ("Provider=ADsDSOObject;")
$objCommand = CreateObject("ADODB.Command")
$objCommand.ActiveConnection = $objConnection
$objCommand.CommandText =
"<LDAP://" + $strDomain + ">;((saMAccountName=" + $userName + "))" +
";distinguishedName,name;subtree"

$objRecordSet = $objCommand.Execute

While Not $objRecordSet.EOF
$dn = $objRecordSet.Fields("distinguishedName").Value
$getOU = $dn
$objRecordSet.MoveNext
loop
endfunction

_________________________
Eric