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
Try this
Agent procedure attached
And save this as aduserinfo.vbs then upload to your VSA
------------------------------------------------------------------------
Const Overwrite = TRUEConst OUTPUT_FILE = "accounts.txt"Set ArgObj = WScript.ArgumentsIf ArgObj.Count <> 1 Then Wscript.Echo "Incorrect number of arguments provided." Wscript.Quit(GENERAL_FAILURE)End If' Set filesystem variableslocalPath = argObj(0)outputFile = localPath & "\" & OUTPUT_FILE' Create and open result output fileSet objFSO = CreateObject("Scripting.FileSystemObject")Set objResultFile = objFSO.CreateTextFile(outputFile,Overwrite)' Determine DNS domain name.Set objRootDSE = GetObject("LDAP://RootDSE")strDNSDomain = objRootDSE.Get("defaultNamingContext")' File headerobjResultFile.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 = strQueryobjCommand.Properties("Page Size") = 100objCommand.Properties("Timeout") = 30objCommand.Properties("Cache Results") = FalseobjCommand.Properties("Sort On") = "sAMAccountName"Set objRecordSet = objCommand.Execute' Output sorted results to a text filesDo Until objRecordSet.EOFobjResultFile.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 IfNext objResultFile.WriteLine VbCrLf & VbCrLfobjRecordSet.MoveNextLoop' Clean up.objConnection.CloseSet objRootDSE = NothingSet objCommand = NothingSet objConnection = NothingSet objRecordSet = NothingobjResultFile.Close()
-----------------------------------------------------------------------------
Cheers
Paul
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
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