Update all blank email addresses in AD with PowerShell

Update all blank email addresses in AD with PowerShell

Q. How can I set the email address of all users with a blank email address to that of their UPN?

A. Using PowerShell its very easy to change the email address of every user with a blank email to that of their UPN:

$accounts=Get-ADUser -Filter * -Properties mail | where {$_.mail -eq $null} #| select sAMAccountName, UserPrincipalName, mail
foreach($account in $accounts)
{
    $account | Set-ADUser -EmailAddress $account.UserPrincipalName
}

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish