Announcement

Collapse
No announcement yet.

Get Firstname and Surname of User Active Directory

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get Firstname and Surname of User Active Directory

    ########################################
    Set objNetwork = WScript.CreateObject("WScript.Network")
    strUserName = objNetwork.UserName

    Set objOU = GetObject("LDAP://cn=strUserName,ou=students,dc=computing,dc=burton-college,dc=ac,dc=uk")

    fn = objOU.get_FirstName
    sn = objOU.get_LastName

    WScript.Echo objOU.get_FirstName & " " & objOU.get_LastName
    ########################################

    I'm attempting to get the firstname and surname of the user but the LDAP object doesn't seem to work. Can anyone help?

    Thanks

  • #2
    Re: Get Firstname and Surname of User Active Directory

    reported for movement.
    Marcel
    Technical Consultant
    Netherlands
    http://www.phetios.com
    http://blog.nessus.nl

    MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
    "No matter how secure, there is always the human factor."

    "Enjoy life today, tomorrow may never come."
    "If you're going through hell, keep going. ~Winston Churchill"

    Comment


    • #3
      Re: Get Firstname and Surname of User Active Directory

      The objNetwork.UserName accountname is not usable for the cn=strUserName. The LoginName is not used in the distinguished name of the object, the canonical name is.

      samples in the correct vbs syntax,
      Code:
      ' connect to the User object in AD of this (current) user 
      Set objSysInfo = CreateObject("ADSystemInfo")
      userDN = objSysInfo.username
      Set objUser = GetObject("LDAP://" & userDN)
      
      ' cache all the used attributes of the user (optional, for better performance on multiple attr calls)
      objUser.GetInfoEx Array("GivenName","SN"), 0
      
      
      WScript.Echo objUser.Get("GivenName"), objUser.Get("SN")
      'or
      WScript.Echo objUser.GivenName, objUser.SN, "["& objUser.DisplayName &"]"
      
      'or
      
      fn = objUser.Get("GivenName")
      sn = objUser.Get("SN")
      
      WScript.Echo fn, sn
      \Rems

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment

      Working...
      X