How to Update User’s Email Address in SharePoint using PowerShell?
Problem: SharePoint workflows failed because the user has no email address!
You can get the user’s Email address with this PowerShell one-liner:
(Get-SPUser -Identity "Crescent\bourgeois" -Web "https://portal.crescent.com/projectpipeline").email
The solution is simple! SharePoint user has no email address, so add the email address to users to resolve the issue!
How to update SharePoint user email address?
Maybe you know you can’t do it using the web browser UI, but you have to use PowerShell instead! In this blog post, I’ll show you how to update a user’s email address in SharePoint using PowerShell. To update user email address, Use, Set-SPUser cmdlet. Here are some examples:
Syntax:
Set-SPUser -Identity "i:0#.w|Domain\username" -Email "email@domain.com" -Web https://sharepoint-site-url
Example:
Set-SPUser -Identity "i:0#.w|Crescent\Salaudeen" -Email "Salaudeen@crescent.com" -Web https://intranet.crescent.com/
This sets the Email ID of the user with Email for the entire site collection.
Change user email address from Active Directory:
You can Sync the User’s Email ID from Active Directory
Set-SPUser -Identity "i:0#.w|Domain\username" -Web "https://sharepoint-site-url" -SyncFromAD
Set-SPUser -Identity "i:0#.w|Crescent\Salaudeen" -Web "https://intranet.crescent.com/" -SyncFromAD
This script syncs user properties such as Display Name, Email, Department, etc. from the Active directory. Here is the result of the updated user email:
PowerShell script to update the User Email address for all Sites in the web application:
Use this script to update the user’s Email address for the entire web application.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$WebAppURL="https://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 "Salaudeen@crescent.com" -Web $_.Rootweb.URL
}
}
To Sync All user details such as email, display Name, etc from the Active directory, use:
Get-SPUser -Web https://web-app-url | Set-SPUser -SyncFromAD
Hi
I tried this Get-SPUser -Web https://web-app-url | Set-SPUser –SyncFromAD, but gives error – can not get the full name or email address of user error- any inputs pls.
Thanks for sharing. It worked very well.
How to Update User Email Address in SharePoint 2007 using stsadm.exe ?
Could you please send the command for SP 2007.
Try Full profile Import!