Saturday, March 21, 2015

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 "").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:
Set-SPUser -Identity "i:0#.w|Domain\username" -Email "" -Web http://sharepoint-site-url
Set-SPUser -Identity "i:0#.w|Crescent\Salaudeen" -Email "" -Web
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 "" -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

#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 "" –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

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...