How to Update User Email Address in SharePoint using PowerShell?

Problem: SharePoint workflows failed because, user has no email address!
sharepoint change user email address
You can get the user's Email address with this PowerShell one-liner:
(Get-SPUser -Identity "Crescent\bourgeois" -Web "http://portal.crescent.com/projectpipeline").email

Solution is simple! SharePoint user has no email address, so add email address to users to resolve the issue!

How to update SharePoint user email address?
To update user email address, Use, Set-SPUser cmdlet. Here are some examples:
Syntax:
Set-SPUser -Identity "i:0#.w|Domain\username" -Email "[email protected]" -Web http://sharepoint-site-url
Example:
Set-SPUser -Identity "i:0#.w|Crescent\Salaudeen" -Email "[email protected]" -Web http://intranet.crescent.com/
This sets the Email ID of the user to given Email for entire site collection.

Change user email address from Active Directory:
You can Sync User's Email ID from Active Directory
Set-SPUser -Identity "i:0#.w|Domain\username" -Web "http://sharepoint-site-url" -SyncFromAD

Set-SPUser -Identity "i:0#.w|Crescent\Salaudeen" -Web "http://intranet.crescent.com/" -SyncFromAD
This script syncs user properties such as Display Name, Email, Department, etc from Active directory. Here is the result of updated user Email:
update user email in sharepoint

PowerShell script to update User Email address for all Sites in the web application:
Use this script to update user's Email address for the entire web application.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
$WebAppURL="http://intranet.crescent.com"
$UserAccount="i:0#.w|Crescent\Salaudeen"

#Update Email for all sites in the web application
Get-SPWebApplication $WebAppURL | Get-SPSite -Limit All | Foreach-object {
    
    Write-host "Processing:" $_.Rootweb.URL

    #Get the User's Current Display Name and E-mail
    $User = Get-SPUser -Identity $UserAccount -Web $_.Rootweb.URL

    if($User -ne $null)
    {
        Set-SPUser -Identity "i:0#.w|Crescent\Salaudeen" -Email "[email protected]" –Web $_.Rootweb.URL
    }
}
To Sync All user details such as Email, Display name, etc from Active directory, use:
Get-SPUser -Web http://web-app-url | Set-SPUser –SyncFromAD

3 comments:

  1. How to Update User Email Address in SharePoint 2007 using stsadm.exe ?
    Could you please send the command for SP 2007.

    ReplyDelete
  2. Thanks for sharing. It worked very well.

    ReplyDelete

Please Login and comment to get your questions answered!

Powered by Blogger.