Kaseya Community

Active Directory Users

  • Does anyone have a script that would export active directory users along with their email addresses?

    Legacy Forum Name: Active Directory Users,
    Legacy Posted By Username: kdog3445
  • i need one one like this but to list users, emails, and member access groups.

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: Iggy1328
  • If you use LDIF and export to a CSV, then upload to Kaseya I think you would have what you need. LDIF can grab all AD attributes.

    Legacy Forum Name: Kaseya2 Scripts,
    Legacy Posted By Username: rdwilkerson
  • Whats the command to just export username and email address?

  • This is what I use:

    dsquery * -filter "(&(sAMAccountType=805306368)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))" -limit 0 | dsget user -display -email -dept -title >> C:\temp\ActiveADUsers.txt

    Then collect the txt file to my Kaseya server

  • Thanks!!

  • Alistair,

    What does this part of the command do: "(&(sAMAccountType=805306368)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"    ??

    Also is there a way to show if user is disabled or not?

  • That part tells it to omit disabled users.  Not tested but you can probably omit and show them all.

  • Hi all,

    Is it possible to query one user's email address with just his login name ?

  • I shall now put my hand up and admit I'm now out of my comfort zone

  • Procedure MMS List AD User and Email Info.xml

    Try this

    Agent procedure attached

    And save this as aduserinfo.vbs then upload to your VSA

    ------------------------------------------------------------------------

    Const Overwrite = TRUE
    Const OUTPUT_FILE = "accounts.txt"

    Set ArgObj = WScript.Arguments

    If ArgObj.Count <> 1 Then
    Wscript.Echo "Incorrect number of arguments provided."
    Wscript.Quit(GENERAL_FAILURE)
    End If

    ' Set filesystem variables
    localPath = argObj(0)
    outputFile = localPath & "\" & OUTPUT_FILE

    ' Create and open result output file
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objResultFile = objFSO.CreateTextFile(outputFile,Overwrite)

    ' Determine DNS domain name.
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strDNSDomain = objRootDSE.Get("defaultNamingContext")

    ' File header
    objResultFile.WriteLine "USER ACCOUNT INFORMATION FOR DOMAIN: " & strDNSDomain & VbCrLf

    ' Use ADO to search Active Directory.
    Set objCommand = CreateObject("ADODB.Command")
    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    objCommand.ActiveConnection = objConnection

    ' Specify the base of the search.
    strBase = "<LDAP://" & strDNSDomain & ">"

    ' Filter on all user objects in the domain.
    strFilter = "(& (objectCategory=person)(objectClass=user)(proxyAddresses=*))"

    ' Specify the attributes to retrieve (comma delimited list).
    strAttributes = "sAMAccountName,proxyAddresses"

    ' Specify the query. "subtree" means to search all child containers/OU's.
    strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

    objCommand.CommandText = strQuery
    objCommand.Properties("Page Size") = 100
    objCommand.Properties("Timeout") = 30
    objCommand.Properties("Cache Results") = False
    objCommand.Properties("Sort On") = "sAMAccountName"
    Set objRecordSet = objCommand.Execute

    ' Output sorted results to a text files
    Do Until objRecordSet.EOF
    objResultFile.WriteLine "Account Name: " & objRecordSet.Fields("sAMAccountName")
    objResultFile.WriteLine "Email Address(es): "
    objResultFile.WriteLine ""
    For Each emailAddress in objRecordSet.Fields("proxyAddresses").Value
    If StrComp(Left(emailAddress, 4),"SMTP") = 0 Then
    objResultFile.WriteLine objRecordSet.Fields("sAMAccountName")& VbTab & VbTab & Mid(emailAddress,6) & " " & "(Primary)"
    End If
    If StrComp(Left(emailAddress, 4),"smtp") = 0 Then
    objResultFile.WriteLine objRecordSet.Fields("sAMAccountName") & VbTab & VbTab & Mid(emailAddress,6)
    End If
    Next
    objResultFile.WriteLine VbCrLf & VbCrLf
    objRecordSet.MoveNext
    Loop

    ' Clean up.
    objConnection.Close
    Set objRootDSE = Nothing
    Set objCommand = Nothing
    Set objConnection = Nothing
    Set objRecordSet = Nothing

    objResultFile.Close()

    -----------------------------------------------------------------------------

    Cheers

    Paul

  • aduserinfo.txt

    here's the vb so you can just download and save it

    You'll need to rename the file and give it a .vbs extension



    [edited by: Paul Haaker at 3:53 AM (GMT -7) on 1 Aug 2012] ABC
  • Hi Guys,

    Thanks for the input.....  for this is what I needed :  script needs AgentTempDir as an argument.

    Option Explicit

    Const ForWriting = 2

    WScript.Timeout= 30

    Dim objUser, objADSysInfo,b,sAgentTemp

    Dim fso

    sAgentTemp = WScript.Arguments(0)

    Set fso = WScript.CreateObject("Scripting.Filesystemobject")

    Set objADSysInfo = CreateObject("ADSystemInfo")

    Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)

    Set b = fso.CreateTextFile(sAgentTemp & "\email.txt",2)

    b.WriteLine objUser.Mail

    b.Close

  • This post has been deleted.
  • This post has been deleted.