break on
$AttrName = "memberof"
$ObjName = "TestUser"
$objCommand = CreateObject("ADODB.Command")
$objConnection = CreateObject("ADODB.Connection")
$objConnection.Provider = "ADsDSOObject"
$objConnection.Open("Active Directory Provider")
$objCommand.ActiveConnection = $objConnection
; define initial vars for items to be read
$objRootDSE = GetObject("LDAP://rootDSE")
$defaultNamingContext = $objRootDSE.Get("defaultNamingContext")
; define the query statement
$objCommand.CommandText = "Select $AttrName from 'LDAP://$defaultNamingContext' WHERE sAMAccountName='" + $ObjName + "'"
; and execute it
$Recordset = $objCommand.Execute
$strURL = $Recordset.Fields("$AttrName").Value
for $x = 0 to ubound($strURL)
$arrGROUP = split($strURL[$x],",")
$GROUP = SUBSTR($arrGROUP[0],4,len($arrGROUP[0])-3)
$UserIsMemberOf = $UserIsMemberOf + $GROUP + ";"
Next
? $UserIsMemberOf
$objConnection.close