Page 2 of 2 <12
Topic Options
#175285 - 2007-04-07 06:54 AM Re: Dispatch Pointers not allowed in expressions [Re: Allen]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
Thanks, any help will be greatly appriciated.
_________________________
Dale

Top
#175286 - 2007-04-07 06:57 AM Re: Dispatch Pointers not allowed in expressions [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Try changing this line

$filter=" where samAccountName='["+$ADAccountName+"]' "

idea from... http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun05/hey0621.mspx

Top
#175287 - 2007-04-07 07:06 AM Re: Dispatch Pointers not allowed in expressions [Re: Allen]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
Looked like that might be a possible after reading the article, but with the brackets in, it doesn't work with or with out a period.

0 in both for the $recordset.recordcount
_________________________
Dale

Top
#175288 - 2007-04-07 07:20 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Sorry... I'm at my end... but I'd be willing to bet Chris S's fnLDAPQuery() - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=142043&page=1#Post142043 will do what you want. Maybe Chris will check in soon and give you some guidance... or maybe try messing with his example

 Code:
Dim $aAttributes,$sADsPath,$strFilter
Dim $aResults,$c,$r
 
$aAttributes = "mail","telephoneNumber","msExchHomeServerName"
$sADsPath = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")
$strFilter = "(&(objectCategory=person)(objectClass=user)(SAMAccountname="+@UserID+"))"
 
$aResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter)
 
For Each $r in $aResults
    If InStr($r,"=")
        Split($r,"=")[Ubound(Split($r,"="))]
    Else
        $r ?
    EndIf
Next

Top
#175289 - 2007-04-07 07:24 AM Re: Dispatch Pointers not allowed in expressions [Re: Allen]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
Thanks, I will give it a try, am done for the night.
_________________________
Dale

Top
#175300 - 2007-04-08 11:12 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
For splitting characters that are also used by kix, I prefer to avoid confusion and use the Chr() function for the charaters I'd like to Split.

For instance:
 Code:
$x = Split("somestr,ing",Chr(44))

Top
#175303 - 2007-04-09 02:33 PM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Try using TranslateName() UDF to return the distinguuished name of the user object. Then use the DN in the query instead of the sAmAccountName.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#175305 - 2007-04-10 03:15 AM Re: Dispatch Pointers not allowed in expressions [Re: Howard Bullock]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
Howard,
I had considered Translatename(), but had not tried it. If I use this function on an account name the does not have a period in it, it works fine, however, if I try it on an account name that does have a period in it, I get the following (Used your example):

Code I used with the Translatename()
 Code:
$DN = TranslateName (3, "", 3, "@LDomain\kelly.dague", 1)
  ? "DN = " + $DN[0]
  ? "Error = " + $DN[1]
  ? "ErrorText = " + $DN[2]

This is the result
 Quote:
DN =
Error = -2147352567
ErrorText = COM exception error "Set" ((null) - (null)) [-2147352567/80020009]
_________________________
Dale

Top
#175310 - 2007-04-10 04:24 PM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Something may be to be wrong or unexpected concerning your account properties. I have created a new test user in my domain with samAccountName "Howard.Bullock" and ran the attached script which properly returns the DN using TranslateName UDF. (This is an updated version but the internal COM is the same.)

Open the resulting "Props.txt" file that is created in the current directory. Review your properties such as samAccountName to insure that the your account contains the data you expect.

Let me know the result.

Please
 Code:
Break on

DEL "Props.txt"

$rc=SETOPTION ("WrapAtEOL","ON")

  Dim $NameArray
  $NameArray = TranslateName (3, "", 3, "@ldomain\Howard.Bullock", "1,2")
  if @error=0
    $UserDN            = $NameArray[1]
    $UserCanonicalname = $NameArray[2]
    ? "UserDN = " + $UserDN ?
    ? "UserCanonicalname = " + $UserCanonicalname ?
    WriteLog2("Props.txt", "UserDN = " + $UserDN)
    WriteLog2("Props.txt", "UserCanonicalname = " + $UserCanonicalname)
     WriteLog2("Props.txt","")
  else
    ? @serror
  endif
? ?
$object = getobject("LDAP://" + substr(%LogonServer%,3) + "/"+$UserDN)
EnumObjProps($object)

;--------------------------------------------------------------------------------------------------
;FUNCTION         EnumObjProps()
;
;AUTHOR           Howard A. Bullock (hbullock@tycoelectronics.com)
    
Function EnumObjProps($object)
   Dim $Class, $Schema, $Value, $property, $cont

   $Class = GetObject($object.schema)
    ? "Class: " + $Class.Name
    WriteLog2("Props.txt", "Class: " + $Class.Name)
    ? "GUID: " + $Class.GUID
    WriteLog2("Props.txt", "GUID: " + $Class.GUID)
    ? "Implemented by: " + $Class.CLSID
    WriteLog2("Props.txt", "Implemented by: " + $Class.CLSID)

    If $Class.Container
        ? ? "Container Object"
        WriteLog2("Props.txt", "Container Object")
        ? "Class Contains:"
        WriteLog2("Props.txt", "Class Contains:")
        For Each $cont In $Class.Containment
            ? "   " + $cont
            WriteLog2("Props.txt", "   " + $cont)
        Next
    Else
        ? ? "Leaf Object"
            WriteLog2("Props.txt", "Leaf Object")
    EndIf

    ? "Mandatory Properties in this Class: "
    For Each $property In $Class.MandatoryProperties
        ? "   " + $property
        $val =""
        if $property <> "nTSecurityDescriptor" and
           $property <> "objectClass"
          $RC=EXECUTE("$$VAL = $$object.$property")
        " " +$val
        WriteLog2("Props.txt", $property + " = " + $val)
    endif
    Next

    ? ?  "Optional Properties in this Class: "
    For Each $property In $Class.OptionalProperties
        ? "   " + $property
        $val =""
        if $property <> "logonHours"  and
           $property <> "dSCorePropagationData" and
           $property <> "accountExpires" and
           $property <> "badPasswordTime" and
           $property <> "lastLogoff" and
           $property <> "lastLogon" and
           $property <> "lockoutTime" and
           $property <> "memberOf" and
           $property <> "pwdLastSet" and
           $property <> "uSNChanged" and
           $property <> "uSNCreated" ;and
           ;left($property, 5) <> "mS-DS"

          $RC=EXECUTE('$$VAL = $$object.get("$property")')
          " = " + $val
        endif
        WriteLog2("Props.txt", $property + " = " + $val)
    Next
EndFunction


;--------------------------------------------------------------------------------------------------
;FUNCTION         TranslateName()
;
;AUTHOR           Howard A. Bullock (hbullock@tycoelectronics.com)
;
;VERSION          3.0
;
;ACTION           Translates from one name type to another. Good for converting an NT4 name
;                 like domain\user into an LDAP distinguished name or the reverse.
;
;SYNTAX           TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)
;
;DATE             2005/04/22
;
;PARAMETERS       $InitType (Required)
;                  -  Integer value
;                     1 = ADS_NAME_INITTYPE_DOMAIN
;                     Initializes a NameTranslate object by setting the domain that the object will bind to.
;
;                     2 = ADS_NAME_INITTYPE_SERVER
;                     Initializes a NameTranslate object by setting the server that the object will bind to.
;
;                     3 = ADS_NAME_INITTYPE_GC
;                     Initializes a NameTranslate object by locating the global catalog that the object will bind to.
;
;                 $BindName (Required)
;                  -  String value
;                     If an $InitType = 3 (ADS_NAME_INITTYPE_GC), then the $BindName = "".
;                     InitTypes 1 and 2 require a name of a domain or server to be input. Note: "" may default
;                     to the current server or domain.
;
;                 $LookupNameType (Required)
;                  -  Integer value
;
;                 $LookupName (Required)
;                  -  String value see below
;
;                 $ReturnNameType (Required)
;                  -  single Integer or comma separated string of numbers
;
;                  Documentation of Name Types. Lookup the more info on http://MSDN.Microsoft.com
;                  Not all name types work. The two that have been most useful to are "1" and "3"
;
;                 1 = ADS_NAME_TYPE_1779
;                 Name format as specified in RFC 1779. For example, "CN=Jane Doe,CN=users, DC=Microsoft, DC=com".
;
;                 2 = ADS_NAME_TYPE_CANONICAL
;                   Canonical name format. For example, "Microsoft.com/Users/Jane Doe".
;
;                 3 = ADS_NAME_TYPE_NT4
;                 Account name format used in Microsoft® Windows© NT® 4.0. For example, "Microsoft\JaneDoe".
;
;                 4 = ADS_NAME_TYPE_DISPLAY
;                 Display name format. For example, "Jane Doe".
;
;                 5 = ADS_NAME_TYPE_DOMAIN_SIMPLE
;                 Simple domain name format. For example, "JaneDoe@Microsoft.com".
;
;                 6 = ADS_NAME_TYPE_ENTERPRISE_SIMPLE
;                 Simple enterprise name format. For example, "JaneDoe@Microsoft.com".
;
;                 7 = ADS_NAME_TYPE_GUID
;                 Global Unique Identifier format. For example, {95ee9fff-3436-11d1-b2b0-d15ae3ac8436}.
;
;                 8 = ADS_NAME_TYPE_UNKNOWN
;                 Unknown name type. The system will try to make the best guess.
;
;                 9 = ADS_NAME_TYPE_USER_PRINCIPAL_NAME
;                 User principal name format. For example, "JaneDoe@Fabrikam.com".
;
;                 10 = ADS_NAME_TYPE_CANONICAL_EX
;                 Extended canonical name format. For example, "Microsoft.com/Users Jane Doe".
;
;                 11 = ADS_NAME_TYPE_SERVICE_PRINCIPAL_NAME
;                 Service principal name format. For example, "www/www.microsoft.com@microsoft.com"
;
;                 12 = ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME
;                 A SID string, as defined in the Security Descriptor Definition Language (SDDL), for either
;                 the SID of the current object or one from the object's SID history.
;                 For example, "O:AOG:DAD:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)" For more information see
;                 Security Descriptor String Format under "Security" in the Microsoft Platform SDK documentation.
;
;REMARKS          Not all name types seem to work. $ReturnNameType can be a single number or a comma separated
;                 list of numbers. The resulting array will have the coresponding array elements populated
;                 with the specific names requested.
;
;RETURNS          This function returns a 13 element ARRAY. Use the array element that corresponds to the
;                 number of the name type listed above.
;
;DEPENDENCIES     OS: Active Directory aware client
;
;EXAMPLES
;
; These two examples attempt to retrieve all names
; $Names = TranslateName (3, "", 3, @Domain + "\" @wksta + "$", "1,2,3,4,5,6,7,8,9,10,11,12")
; Dim $x
; ? "Ubound = " + ubound($names)
; for $x=0 to ubound($Names)
;   ? ""+ $x +": " + $Names[$x]
; next
; ?
; $Names = TranslateName (3, "", 3, @LDomain + "\" + @userid, "1,2,3,4,5,6,7,8,9,10,11,12")
; Dim $x
; ? "Ubound = " + ubound($names)
; for $x=0 to ubound($Names)
;   ? ""+ $x +": " + $Names[$x]
; next
;
; Get Distinguished Name (Name type #1)
; $Names = TranslateName (3, "", 3, @LDomain + "\" + @userid, 1)
; ? "DN = " + $Names[1]
;
;
Function TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)
  Dim $NameTranslate, $Error, $ErrorText, $ReturnNameArray[12], $GetNameArray, $value

  $Error = 0
  $ErrorText = ""
  $ReturnName = ""

  $NameTranslate = CREATEOBJECT ("NameTranslate")
  $Error = @error
  $ErrorText = @serror
  if $Error = 0
    $NameTranslate.Init ($InitType, $BindName)
    $Error = @error
    $ErrorText = @serror
    if $Error = 0
      $NameTranslate.Set ($LookupNameType, $LookupName)
      $Error = @error
      $ErrorText = @serror
      if $Error = 0
        Dim $index
        $GetNameArray = split($ReturnNameType, ",")
        for $index=0 to ubound($GetNameArray)
          $value = $GetNameArray[$index]
          $ReturnNameArray[$value] = $NameTranslate.Get($value)
        next
      else
        WriteLog("TranslateName SET Error: (" + $Error + ") " + $ErrorText)
        exit $Error
      endif
    else
      WriteLog("TranslateName INIT Error: (" + $Error + ") " + $ErrorText)
      exit $Error
    endif
  else
    WriteLog("TranslateName CREATEOBJECT Error: (" + $Error + ") " + $ErrorText)
    exit $Error
  endif
  $TranslateName = $ReturnNameArray
  Exit 0
Endfunction

;--------------------------------------------------------------------------------------------------
;FUNCTION         WriteLog2()
;
;AUTHOR           Howard A. Bullock (hbullock@tycoelectronics.com)
;
;ACTION           Generic logging facility for scripts. Appends log entry to a file with an
;                 optional TimeStamp.
;
;SYNTAX           WriteLog2($File, $text, [0|1])
;
;PARAMETERS       $File (Required) -  String value
;                 $text (Required) -  String value
;                 $TimeStamp (Optional) Default(0) no TimeStamp (1 or 0)
;
;
;REMARKS          This function writes (appends) an optionally time stamped log entry to the file
;                 defined in function. This function searches for the first unused file handle,
;                 open the file, and write the entry. The file handle is then closed. When the
;                 function is unable to perform its it write the error is displayed in a message box.
;
;RETURNS          Nothing
;
;DEPENDENCIES     None
;
;EXAMPLES         WriteLog2("junk.txt","This is a test")
;                 WriteLog2("junk.txt","This is a test",0)
;                 WriteLog2("junk.txt","This is a test",1)
;
;
Function WriteLog2($File, $Text, optional $TimeStamp)
   dim $RC, $File, $text, $FH, $TimeStamp, $nul
   $FH=1
   $RC=Open ($FH, $File, 5)
   while $RC = -3 and $FH < 11
      $FH=$FH +1
      $RC=Open ($FH, $File, 5)
   Loop
   Select
      Case $RC=0
            if ($TimeStamp=1)
               $TimeStamp = @Date + " " + @Time + " - "
            else
               $TimeStamp = ""
            endif
            $RC=Writeline ($FH, $TimeStamp + $Text + @CRLF)
            if ($RC <> 0)
              $text = "WriteLine error: $RC @CRLF  -4 = File not open for writing@CRLF" +
                       "  -3 = File number not open@CRLF  -2 =  Invalid file number specified@CRLF" +
                        "  -1 = End of file"
              $nul=MessageBox ($text,"Script Error",48)
            endif
            $nul=Close ($FH)
            exit $RC
      Case $RC=-2
         $text = "WriteLog2: Invalid file handle ($FH) specified when trying to Open $File."
         $nul=MessageBox ($text,"Script Error",48)

      Case $RC=-1
         $text = "WriteLog2: Invalid file name ($File) specified for log file."
         $nul=MessageBox ($text,"Script Error",48)

      Case $RC=>0
         $text = "System Error($RC) while attempting to open log file ($File)."
         $nul=MessageBox ($text,"Script Error",48)

   Endselect
   exit $RC
EndFunction
 
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#175311 - 2007-04-10 04:27 PM Re: Dispatch Pointers not allowed in expressions [Re: Howard Bullock]
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
If the script provided above does not work for your account with a period. I suggest you use LDP.exe to bind to your domain and view the properties of the account is question.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#175352 - 2007-04-12 04:39 AM Re: Dispatch Pointers not allowed in expressions [Re: Howard Bullock]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
I have tried your new script and it does work for most accounts with a period. There are a few that still have trouble and I will have to research them. I should be able to use the DN to pull the homemdb attribute. Hopefully I can make this work. It will save us a lot of manual work.
Thanks
_________________________
Dale

Top
#175518 - 2007-04-20 04:14 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Daleco Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 23
Loc: Colorado, USA
This is an update to this issue. It is working fine now.

I was reading lines from an Exmerge file with Exchange 2003. I had ASSUMED the name that exmerge was applying to the PST file was the logon name. I discovered this is not the case. It actually pulls the user name from the LegacyExchangeDN which may or may not be the logon name. Therefore the problem with it having a period in the name was only because I was looking for the logon name with data from the LegacyExchangeDN. In those cases where I was having trouble the LegacyExchangeDN and the logon name were not the same, hence the error I was getting.

Howard, the Translatename() was not a fit for this project. Thanks for the suggestion though, it may come in handy elsewhere.

Allen, the fnLDAPQuery() worked perfectly, thanks.

Moral of the story: Always check the source!

Thanks everyone for your assistance.
_________________________
Dale

Top
#175519 - 2007-04-20 05:12 AM Re: Dispatch Pointers not allowed in expressions [Re: Daleco]
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
We are glad to hear that your problem was resolved.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 2 of 2 <12


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.066 seconds in which 0.025 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org