Get-aduser with email emailaddress field

This topic contains 3 replies, has 4 voices, and was last updated by  Naw Awn 1 month, 3 weeks ago.

  • Author
    Posts
  • #6332

    by Christopher.Ellis at 2013-04-26 10:07:43

    I want to run a quick powershell script which reports all users names in our active directory with empty emailaddress field
    I would start the command with get-aduser however the rest not known to me. List produced would be username Populate and emailaddress would be empty.
    Thank you

    by Christopher.Ellis at 2013-04-26 10:24:46

    get-aduser -property 'emailaddress' | select-object -property name, emailaddress

    I got this far, however if I wanted to state emailaddress = empty display name the above command gets all accounts

    by Martin9700 at 2013-04-26 10:30:03

    Kind of a goofy one, evidently Get-ADuser doesn't recognize the $null variable within a filter but I found this to work:

    Get-ADUser -Filter {EmailAddress -notlike "*"} -Properties EmailAddress | Select Name

    by Christopher.Ellis at 2013-04-26 10:41:29

    Thank you

  • #30321

    El Jefe
    Participant

    Instead of the '-notlike "*"' you could use '-le 0'

    • #80641

      Chris McDonald
      Participant

      I needed to do this too, but I needed a list of all the email addresses. I ended up using this:

      Get-ADUser -Filter {EmailAddress -like "*@*"} -Properties * | Select Name, SamAccountName, EmailAddress | Sort Name | Export-csv C:\Scripts\users_with_email_addresses.csv 
  • #80732

    Naw Awn
    Participant

    Hi Chris

    Just run the command below, you will get all AD account with no an email address assigned.

    Get-ADUser -Filter * -Properties mail | Where-Object{$_.mail -like ""} | Format-Table
    
    #If you want to export the result to a csv file...
    Get-ADUser -Filter * -Properties mail | Where{$_.mail -like ""} | 
    Select Name,GivenName,Surname,Enabled,SID | Export-CSV C:\temp\AdUserList-noMail.csv -notype
    
    

    I have tested it so this will work 🙂

You must be logged in to reply to this topic.