-3

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.

1 Answer 1

4
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.

5
  • Now I need to pipe/retrieve those users/objects which are disabled, i.e. Disabled AD Users.
    – Imi
    Jan 3, 2017 at 13:15
  • 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}
    – Tim Haintz
    Jan 3, 2017 at 13:22
  • I want to get disabled users/objects with no email address.
    – Imi
    Jan 3, 2017 at 13:54
  • 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
    – Imi
    Jan 3, 2017 at 14:58
  • 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
    – Tim Haintz
    Jan 3, 2017 at 21:56

Not the answer you're looking for? Browse other questions tagged .