Retrieving Active Directory Users with no Email address

10,675
get-aduser -filter * -properties * | where {!$_.emailaddress} | select-object samaccountname | export-csv c:\email\noemailusers.csv

This gets all AD users with all properties. It then checks each user/object and if they do not have an emailaddress property, pipe them to the select-object cmdlet and display the samaccountname, this then gets piped to export-csv where the file is created.

You could modify the select-object cmdlet if you want to preserve more information than just the samaccountname.

Hope this helps.

Thanks, Tim.

Share:
10,675

Related videos on Youtube

Imi
Author by

Imi

Updated on September 18, 2022

Comments

  • Imi
    Imi almost 2 years

    There are 1000+ users in AD. Some random users accounts (approx. 400) are created without Email address. Now I need to retrieve all those users in an Excel file who are there without Email Address. The purpose is to add the missing Email addresses manually.

  • Imi
    Imi over 7 years
    Now I need to pipe/retrieve those users/objects which are disabled, i.e. Disabled AD Users.
  • Tim Haintz
    Tim Haintz over 7 years
    Do you want the disabled users first or the disabled users and no email address? If you just want disabled users get-aduser -filter {Enabled -eq $False}
  • Imi
    Imi over 7 years
    I want to get disabled users/objects with no email address.
  • Imi
    Imi over 7 years
    i edited the cmdlet and it looks fine but not sure if its correct. Because when I retrieve only disabled users and match it with the one with 'no email users' then there is a difference of users. get-aduser -filter * -properties * | where {!$_.emailaddress} | select-object samaccountname, AccountDisabled | export-csv c:\noemailusers.csv
  • Tim Haintz
    Tim Haintz over 7 years
    The first script you were getting all users with no email address. The second one you were filtering for disabled users first, then you could pipe them to check for email address. get-aduser -filter {Enabled -eq $False} | where {!$_.emailaddress} . If you want to export the samaccountname and if they are enabled/disabled, you will need to use select-object samaccountname,enabled You are asking for the enabled property. Your CSV will then display the value of that property for each user (True or False). Thanks,Tim