| 
| 
| 
| #208061 - 2013-11-27 04:55 AM  LDAP canonicalName |  
| Howard Bullock   KiX Supporter
 
       
   Registered:  2000-09-15
 Posts: 5809
 Loc:  Harrisburg, PA USA
 | 
The attribute canonicalName has been problematic for us previously. I had hoped this would now just work, but alas that attribute does not seem to translate via KiX. 
 Has anyone been able to use an ADO LDAP query to return canonicalName?
 
 
 $ADS_SCOPE_SUBTREE = 2
$objConnection = CreateObject('ADODB.Connection')
$objCommand = CreateObject('ADODB.Command')
$objConnection.Provider = 'ADsDSOObject'
$objConnection.Open('Active Directory Provider')
$objCommand.ActiveConnection = $objConnection
$objCommand.CommandText = "SELECT distinguishedName, canonicalName, cn, employeeID, department FROM 'LDAP://dc=domain,dc=pheaa,dc=org' WHERE objectCategory='user' and sAMAccountName='user1'"
$objRecordSet = $objCommand.Execute()
$distinguishedName = $objRecordSet.Fields('distinguishedName').Value
;$canonicalName     = $objRecordSet.Fields('canonicalName')        ;script error
$canonicalName     = $objRecordSet.Fields('canonicalName').item(0) ; 0
;$canonicalName     = $objRecordSet.Fields('canonicalName').Value   ;script error
$cn                = $objRecordSet.Fields('cn').Value
$employeeID        = $objRecordSet.Fields('employeeID').Value
$department        = $objRecordSet.Fields('department').Value
"var=" + vartype($canonicalName)
? $distinguishedName
? $canonicalName
? $cn
? $employeeID
? $department
?
 
 var=8204
CN=Bullock\, Howard A (P609154),CN=Users,DC=domain,DC=pheaa,DC=org
ERROR : Error in expression: this type of array not supported in expressions.!
Script: C:\data\Automation\LogonScript\test.kix
Line  : 22
 
 
 Edited by Howard Bullock (2013-11-27 04:55 AM)
 |  
| Top |  |  |  |  
| 
| 
| #208064 - 2013-11-27 11:55 AM  Re: LDAP canonicalName
[Re:  Allen] |  
| Allen   KiX Supporter
 
       
 Registered:  2003-04-19
 Posts: 4562
 Loc:  USA
 | 
Try this...
 
 
$CanonicalName=Join($objRecordSet.Fields("canonicalName").Value)
 |  
| Top |  |  |  |  
| 
| 
| #208071 - 2013-11-27 03:04 PM  Re: LDAP canonicalName
[Re:  Allen] |  
| Howard Bullock   KiX Supporter
 
       
   Registered:  2000-09-15
 Posts: 5809
 Loc:  Harrisburg, PA USA
 | 
I get:
 87 The parameter is incorrect.
 
 After using your suggested "Join". This is not serious because I can get the data using my TranslateName() UDF. I just have always been annoyed with KiX getting canonicalName. Since LDAP is the supported, I just would like to see if there is a way to query this value because I can do it in Perl.
 |  
| Top |  |  |  |  
| 
| 
| #208072 - 2013-11-27 03:26 PM  Re: LDAP canonicalName
[Re:  Howard Bullock] |  
| Allen   KiX Supporter
 
       
 Registered:  2003-04-19
 Posts: 4562
 Loc:  USA
 | 
Not sure why it didn't work, but here is one of my working tests...  I changed your code a little to get a specific user and modified the way the ADO query was put together... The only line you will have to change below is $DN=GetUserDN("") if you want to target a specific user, otherwise it will get the currentuser.  If this doesn't work for you, I have another piece of code that  I worked on this last night, although its not as straight forward as the code below.
 
 
 
$ADS_SCOPE_SUBTREE = 2
$objConnection = CreateObject('ADODB.Connection')
$objCommand = CreateObject('ADODB.Command')
$objConnection.Provider = 'ADsDSOObject'
$objConnection.Open('Active Directory Provider')
$objCommand.ActiveConnection = $objConnection
$DN=GetUserDN("")
? $DN
$strBase = "<LDAP://" + $DN +  ">"
$strFilter = "(&(objectCategory=person)(objectClass=user))"
$strAtt="distinguishedName, canonicalName, cn, employeeID, department"
$strQuery = $strBase + ";" + $strFilter + ";" + $strAtt + ";subtree"
$objCommand.CommandText=$strQuery
$objRecordSet = $objCommand.Execute()
$CanonicalName=Join($objRecordSet.Fields("canonicalName").Value)
? $CanonicalName
Function getUserDN(optional $username)
  Dim $objTrans
  if $username=""
    $username=@ldomain + "\"+ @userid
  endif
  if not instr($username,"\")
    $username=@ldomain + "\" + $username
  endif
  $objTrans = CreateObject("NameTranslate")
  if @error
    exit @error
  else
    $objTrans.Init(3, "")
    $objTrans.Set(3,$username)
    $getUserDN = $objTrans.Get(1)
    if @error
      exit @error
    endif
  endif
EndFunction
 |  
| Top |  |  |  |  
| 
| 
| #208076 - 2013-11-27 09:17 PM  Re: LDAP canonicalName
[Re:  Allen] |  
| Howard Bullock   KiX Supporter
 
       
   Registered:  2000-09-15
 Posts: 5809
 Loc:  Harrisburg, PA USA
 | 
User error!!  The use of the "Join" function did fix the problem. When I tested previously, I copied my test code form this thread which had the query data changed from my production values and I failed to truly look at the result when it failed. Sorry.
 Thanks for the solution.
  One that I should have been able to find.   |  
| Top |  |  |  |  
| 
| 
| #208077 - 2013-11-27 10:37 PM  Re: LDAP canonicalName
[Re:  Howard Bullock] |  
| Allen   KiX Supporter
 
       
 Registered:  2003-04-19
 Posts: 4562
 Loc:  USA
 | 
LOL.  Good to hear you got it sorted out.  (Rookie  ) |  
| Top |  |  |  |  
 Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
 
 | 
| 
 
| 0 registered
and 739 anonymous users online. 
 | 
 |  |