# If a user has incorrect information showing in their CMDNET user profile in SharePoint this script can correct
# Add their information to the following 3 variables (the Email and Display Name are the only ones users wanted changed so far)
$username = "PSNS\ps***"
$mail = "firstname.lastname@navy.mil"
$displayname = "lastname, firstname"
$jobtitle = " "
Write-Host "Changing information for $username"
foreach($site in Get-SPSite -Limit ALL)
{
$web = $site.RootWeb
# Loop through all sites collections except the central administration. This allows the code to work on test or prod by not having to use the URL.
if($web.Url -like "*homeportnw*")
{
Write-Host $web.Url
$list = $web.Lists["User Information List"]
$query = New-Object Microsoft.SharePoint.SPQuery
$query.Query = "<Where><Eq><FieldRef Name='Name' /><Value Type='Text'>$username</Value></Eq></Where>"
$userInformationListItems = $list.GetItems($query)
if ($userInformationListItems -ne $null)
{
foreach($userInformationListItem in $userInformationListItems)
{
# Remove the remark from the next line to display which site collections the user exists in and their display name:
# echo $userInformationListItem["Title"]
# "Title" here is the same as "Name" in User Info List and "EMail" = "Work e-mail" and "Name" = "Account"
# ******* Run these 2 next sections separately ********
# Remove the remarks from the next 2 lines to change the user's Email:
# $userInformationListItem["EMail"] = $mail
# $userInformationListItem.SystemUpdate()
# Remove the remarks from the next 2 lines to change the user's Display Name:
$userInformationListItem["Title"] = $displayname
$userInformationListItem.SystemUpdate()
# Remove the remarks from the next 2 lines to change the user's Job Title:
# $userInformationListItem["JobTitle"] = $jobtitle
# $userInformationListItem.SystemUpdate()
}
} else {
echo "Not in this site collection"
}
}
}