Ldap query to find all users with a certain alias

What query can be used to find all users that have an alias with @domainB.com?  I see how to find the primary ones, but not aliases.  If the query could also return the users name and what all the aliases are, that would be useful as well.
LVL 1
TacoFlavoredKissesAsked:
Who is Participating?
 
pubeheedConnect With a Mentor Commented:
slight change export-csv does not hand the proxy address so use out-file instead - not the best output but it should do the job

you should be able to import the file into excel format by opening excel and then importing the txt file using fixed sized fields as the delimiter./

Good luck

GM
get-qaduser -sizelimit 0 -ldapfilter "(proxyAddresses=*@domainB.com)" -IncludedProperties proxyAddresses | select samaccountname,displayname,proxyAddresses | out-file c:\temp\aliasinfo.txt -width 1000

Open in new window

0
 
Chris DentPowerShell DeveloperCommented:
Hey :)

This should do it:

(proxyAddresses=*@domainB.com)

Or did you want those that only have the alias?

You might be better having a script do this for you. Do you have any preference on scripting language?

Chris
0
 
TacoFlavoredKissesAuthor Commented:
vbscript is fine.

Any that have that, regardless of what others they have is fine.  Formatting it so we can tell what user has what would be great.
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
pubeheedCommented:
You could do this in a one liner if you use the powershell quest cmdlets for AD:

http://www.quest.com/powershell/activeroles-server.aspx

The Command below creates a csv file with a list of all users that have @domainb.com in their proxyaddress attribute as well as there accountname and displayname
get-qaduser -sizelimit 0 -ldapfilter "(proxyAddresses=*@domainB.com)" -IncludedProperties proxyAddresses | select samaccountname,displayname,proxyAddresses | export-csv c:\temp\Aliasinfo.csv

Open in new window

0
 
TacoFlavoredKissesAuthor Commented:
Not currently using powershell in this exchange 2003 environment.  
0
 
pubeheedCommented:
Even though it is exchange 2003 you can still use the quest powershell cmdlets on an xp machine to complete the query. No need to install on the server as the attributes are stored in AD so you just need a PC and a standard user who will have read access to AD.

My VB skills are not great so if you need it in VB I will leave it to Chris :-)

Cheers

GM
0
 
Chris DentPowerShell DeveloperCommented:

Sorry, had to sleep.

I would also recommend PowerShell, it's lovely for tasks like this, far more accessible than VbScript.

I'll post a VbScript version in a couple of minutes so you have a full set :)

Pubeheed,

> slight change export-csv does not hand the proxy address

Force it into a string using a custom property and it'll be fine:

Get-QADUser -SizeLimit 0 -LdapFilter "(proxyAddresses=*@domainB.com)" `
  -IncludedProperties proxyAddresses | Select-Object samaccountname, `
    displayname, @{n='EmailAddresses';e={ "$($_.proxyAddresses)" }} | `
  Export-CSV c:\temp\Aliasinfo.csv

Has the same effect as [String]::Join(" ", $_.ProxyAddresses).

Chris
0
 
pubeheedCommented:
cheers Chris !
0
 
Chris DentConnect With a Mentor PowerShell DeveloperCommented:
A quick VbScript version (delay in posting due to being a little busy this morning).

Chris
Const FILE_NAME = "Users.csv"
Const LDAP_FILTER = "(proxyAddresses=*@domainB.com)"

Dim objConnection : Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Dim objCommand : Set objCommand = Createobject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000

Dim objRootDSE : Set objRootDSE = GetObject("LDAP://RootDSE")
objCommand.CommandText = "<LDAP://" & objRootDSE.Get("defaultNamingContext") & ">;" & _
  LDAP_FILTER & ";name,sAMAccountName,mail,proxyAddresses;subtree"

Dim objRecordSet : Set objRecordSet = objCommand.Execute

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.OpenTextFile(FILE_NAME, 2, True, 0)

objFile.WriteLine("Name,Username,PrimaryEmail,EmailAddresses")

Do Until objRecordSet.EOF
  objFile.WriteLine objRecordSet.Fields("Name").Value & "," & _
    objRecordSet.Fields("SamAccountName").Value & "," & _
    objRecordSet.Fields("mail").Value & "," & _
    Join(objRecordSet.Fields("proxyAddresses").Value, " ")

  objRecordSet.MoveNext
Loop

Open in new window

0
 
TacoFlavoredKissesAuthor Commented:
Thanks
0
All Courses

From novice to tech pro — start learning today.