Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm the "script guy" at my work, which is a blessing and a curse... I've been tasked with generating a script of:

Can you create a script to pull all users that have a proxy address that is not an email address out of Active Directory.

What would be the best approach? I'm not sure where the best place to look for this is. I'm researching it now, but since I don't know the best terms to use in my searches... It's taking me longer than I hoped to find something useful.

Utilizing this:

%SystemRoot%\SYSTEM32\rundll32.exe dsquery,OpenQueryWindow  

gives me a lightweight search tool that shows the basics of what I want... the only problem is it doesn't have a "like" or "contains" search function. enter image description here

I need the same kinda search... but with the ability to filter out the proxy addresses that don't contain "".

share|improve this question
+1 for blessing and a curse - I know that feeling all too well – Joe Taylor Sep 28 '11 at 10:46
up vote 2 down vote accepted

Your Question sounds like a job for the PowerShell.

If you don't have PowerShell installed, grab it here. Windows 7 and Server 2008 R2 have PowerShell already installed.

Get the Quest PowerShell Commands for Active Directory. This extension provides handy commands for scripting all kinds of AD operations.

Now for your query:

Note: you can keep this query much simpler, but I'll stretch it out a bit for better understanding.

# Get all Users and save it to a variable. 
#-SizeLimit 0 returns ALL users, otherwise only 1000 are returned.
# -IncludedProperties proxyaddresses makes sure the proxyaddresses are included

$allusers = Get-QADUser -SizeLimit 0 -IncludedProperties proxyaddresses

# Filter Users without a email address and save them to a variable

$filteredusers = $allusers | where {!($_.proxyaddresses -like "*") -and $_.proxyaddresses}

# Sort and output the list

$filteredusers | sort Displayname | format-table Displayname, proxyaddresses -auto

# Other interesting fieldnames you could use with format-table
# GivenName, sn, mail, SamAccountName and many more
# To get a list of all possible field names use: 
# $filteredusers[0] | format-list *
# This will return all fields of the first user saved in $filteredusers
share|improve this answer
Spot on. +10 if I could. Now if I could figure out how to filter out null proxyaddresses as well... where {$_.proxyaddresses -neq ""} doesn't seem to filter. – WernerCD Sep 28 '11 at 14:44
i've updated my post. where{$_.proxyaddresses} does the trick – mich732 Sep 28 '11 at 17:35

This free AD reporting tool might help as you can generate a list to import into a spreadsheet app for more refining - I use it at work for managing our systems:

AD Info - Active Directory Reporting Tool

A flexible Active Directory reporting tool with over 140 built in reports as well as the option to create your own. With more flexability than other Active Directory reporting tools and a modern user friendly interface, AD Info lets you easily query your Active Directory domain for the information you need. Use one of the 140+ queries that come with the application or use the custom query designer to create your own query based on any attributes you choose.

share|improve this answer
Tool looks nice... I'd hate to have to pay $60 for a one-off query (need a "custom" query, since Proxy Address' aren't provided by that tool) – WernerCD Sep 27 '11 at 14:54
Darn. Sorry about that. – Linker3000 Sep 27 '11 at 16:32

using vbscript :

    Set objRoot = GetObject("LDAP://RootDSE") 
    strDNC = objRoot.Get("DefaultNamingContext") 


    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection

    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

    objCommand.CommandText = "SELECT givenNames,sn,telephoneNunmber FROM '" & strDNC & "' WHERE objectCategory='user'" & § " And mail != '*'"
    Set objRecordSet = objCommand.Execute
    strResults = ""
    While Not objRecordSet.EOF
        If strResults = "" Then
            strResults = objRecordSet("givenNames") & "," & objRecordSet("sn") & "," & objRecordSet("telephoneNumber")
            strResults = strResults & VbCrLf & objRecordSet("givenNames") & "," & objRecordSet("sn") & "," & objRecordSet("telephoneNumber")
        End If

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.CreateTextFile("Results.csv", True)
    objFile.Write strResults

    MsgBox "Finished. See Results.csv"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.