Advertisement
jajabro1

userinfo_UPN

Nov 22nd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. On Error Resume Next
  3. Dim objSysInfo, objUser
  4. Set objSysInfo = CreateObject("ADSystemInfo")
  5. DQ = Chr(34)
  6. strUser = ""
  7.  
  8. ' Get the NETBIOS Domain name
  9. Set objSystemInfo = CreateObject("ADSystemInfo")
  10. strDomain = objSystemInfo.DomainShortName
  11.  
  12. ' Prompt for userName
  13. strUserEmail = inputbox("Please enter the users full email address: ")
  14.  
  15. UserNameFromEmail strUserEmail
  16.  
  17. Function UserNameFromEmail(sEmail)
  18.     Const ADS_SCOPE_SUBTREE = 2
  19.     Const PageSize = 1000
  20.     Dim sRootLDAP, oConnection, oCommand, oRecordSet
  21.  
  22.     sRootLDAP = "'LDAP://" & GetObject("LDAP://RootDSE").Get("defaultNamingContext") & "'"
  23.  
  24.     Set oConnection = CreateObject("ADODB.Connection")
  25.     oConnection.Provider = "ADsDSOObject"
  26.     oConnection.Open "Active Directory Provider"
  27.     Set oCommand = CreateObject("ADODB.Command")
  28.     Set oCommand.ActiveConnection = oConnection
  29.     oCommand.CommandText = "Select sAMAccountName from " & sRootLDAP & " Where mail='" & sEmail & "'"
  30.     oCommand.Properties("Page Size") = PageSize
  31.     oCommand.Properties("Timeout") = 30
  32.     oCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
  33.     oCommand.Properties("Cache Results") = True
  34.     Set oRecordSet = oCommand.Execute
  35.     oRecordSet.MoveFirst
  36.     strUser = """"& oRecordSet.Fields(0) & """"
  37.     strUser = Replace(strUser, DQ, "") 'replaces quotations with no spaces.
  38. end function
  39.  
  40. Function GetUserDN(byval strUserName,byval strDomain)
  41.         ' Use name translate to return the distinguished name
  42.         ' of a user from the NT UserName (sAMAccountName)
  43.         ' and the NETBIOS domain name.
  44.  
  45.         Set objTrans = CreateObject("NameTranslate")
  46.         objTrans.Init 1, strDomain
  47.         objTrans.Set 3, strDomain & "\" & strUserName
  48.         strUserDN = objTrans.Get(1)
  49.         GetUserDN = strUserDN
  50. end function
  51.    
  52. Set objUser = GetObject("LDAP://" & GetUserDN(strUser,strDomain))
  53.    
  54. WScript.Echo "GENERAL" & vbCrLf & "=================================================" & vbCrLf & "First name: " & objUser.firstname & vbCrLf & "Last name: " & objUser.sn & vbCrLf & "Display name: " & objUser.displayName & vbCrLf & "" & vbCrLf & "Employee Number: " & objUser.employeeNumber & vbCrLf & "" & vbCrLf & "Description: " & objUser.description & vbCrLf & "Office: " & objUser.physicalDeliveryOfficeName & vbCrLf & "Telephone number: " & objUser.telephoneNumber & vbCrLf & "Other Telephone numbers: " & objUser.otherTelephone & vbCrLf & "Email: " & objUser.mail & vbCrLf & "Web page: " & objUser.wWWHomePage & vbCrLf & "" & vbCrLf & "ADDRESS" & vbCrLf & "=================================================" & vbCrLf &"Street: " & objUser.streetAddress & vbCrLf & "P.O. Box: " & objUser.postOfficeBox & vbCrLf & "City: " & objUser.l & vbCrLf & "State/province: " & objUser.st & vbCrLf & "Zip/Postal Code: " & objUser.postalCode & vbCrLf & "Country/region: " & objUser.c & vbCrLf & "" & vbCrLf & "" & vbCrLf & "ACCOUNT" & vbCrLf & "=================================================" & vbCrLf & "User logon name: " & objUser.userPrincipalName & vbCrLf & "pre-W2K logon name: " & objUser.sAMAccountName & vbCrLf & "AccountDisabled: " & objUser.AccountDisabled & vbCrLf & "" & vbCrLf & "DN: " & objUser.distinguishedName & vbCrLf & "" & vbCrLf & "TELEPHONE" & vbCrLf & "=================================================" & vbCrLf & "Home: " & objUser.homePhone & vbCrLf & "Mobile: " & objUser.mobile & vbCrLf & "Fax: " & objUser.facsimileTelephoneNumber & vbCrLf & "" & vbCrLf & "ORGANIZATION" & vbCrLf & "=================================================" & vbCrLf & "Title: " & objUser.title & vbCrLf & "Department: " & objUser.department & vbCrLf & "Office: " & objUser.physicalDeliveryOfficeName & vbCrLf &"Company: " & objUser.company & vbCrLf & "Manager: " & objUser.manager
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement