Also... this line has vars inside stings... never a good idea...

 Code:
$objCommand.CommandText = "Select $AttrName from 'LDAP://$defaultNamingContext' WHERE sAMAccountName='" + $ObjName + "'"

change to
 Code:
$objCommand.CommandText = "Select " + $AttrName + " from 'LDAP://" + $defaultNamingContext + "' WHERE sAMAccountName='" + $ObjName + "'"