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.
Related videos on Youtube
Author by
Imi
Updated on September 18, 2022Comments
-
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 over 7 yearsNow I need to pipe/retrieve those users/objects which are disabled, i.e. Disabled AD Users.
-
Tim Haintz over 7 yearsDo 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 over 7 yearsI want to get disabled users/objects with no email address.
-
Imi over 7 yearsi 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 over 7 yearsThe 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