PowerShell Genie

Find enabled users without email

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Enabled users are retrieved with the mail attribute requested explicitly, and the intent of the middle stage is to keep only accounts where mail holds nothing.

The script

1PS> Get-ADUser -Filter 'Enabled -eq $true' -Properties mail | Where-Object { -not $_.mail } | Select-Object SamAccountName,Name,DistinguishedName

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 SamAccountName Name DistinguishedName
    2 -------------- ---- -----------------
    3 jdoe Jane Doe CN=Jane Doe,OU=Users,DC=contoso,DC=example
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-ADUser -Filter 'Enabled -eq $true' -Properties mail | Where-Object { -not $_.mail } | Select-Object SamAccountName,Name,DistinguishedName
    1. Stage 1Get-ADUser-Filter -Properties
    2. Stage 2Where-ObjectPositional values or no named parameters
    3. Stage 3Select-ObjectPositional values or no named parameters

      How it works

      Enabled users are retrieved with the mail attribute requested explicitly, and the intent of the middle stage is to keep only accounts where mail holds nothing. The projection carries DistinguishedName alongside the names so you can tell which OU each gap came from.

      Adapting it

      In a hybrid environment, test proxyAddresses rather than mail, since Exchange-managed addresses land there first and the mail attribute can lag behind by a sync cycle.

      Requirements

      ActiveDirectory module.

      If the result is unexpected

      The report lists users who have a mailbox but no AD email value.

      The on-premises mail attribute and the mailbox or cloud address are related but not interchangeable data sources.

      1. Inspect the mail property on a sample user and compare it with the authoritative mail system.

      Validate the result

      The report clearly identifies missing AD mail values rather than claiming that no mailbox exists.

      Keep the check reliable

      State which directory attribute the report evaluates and who owns its population.

      Primary documentation

      PowerShell objects and pipelines documentation

      Continue
      Genie guideFind enabled users without email

      Enabled users are retrieved with the mail attribute requested explicitly, and the intent of the middle stage is to keep only accounts where mail holds nothing.