#该脚本修改某些显示名, email and Active Directory inconsistent accounts
Add-pssnapin Microsoft.SharePoint.PowerShell
$ConfirmPreference = ' None ' #关闭确认提示
$filePath = "C:\file\"
$allUsers =get-content C:\file\user.txt-Encoding UTF8 #从文件中读取需要迁移的账户, each line contains an account and a new display name, a new email address, a---between the fields Open
$WEBAPP =get-spwebapplication "http://wfe1.test.com" #设置需要修改的web application
$allSites = $webApp. Sites
foreach ($site in $allSites)
{
"Querying $site ..."
$SiteUsers =get-spuser-web $site. url.tostring ()
foreach ($siteUser in $SiteUsers)
{
foreach ($user in $allUsers)
{
$account = ($user. ToString ()-split "---") [0]
$newname = ($user. ToString ()-split "---") [1]
$NewEmail = ($user. ToString ()-split "---") [2]
<#
if ($siteuser. ToString ()-split "\|") [1])
{
$userPrefix = ($siteuser. ToString ()-split "\|") [0]
$NewUser = $userprefix + "|" + ($user. ToString ()-split "---") [1]
}
Else
{
$NewUser = ($user. ToString ()-split "---") [1]
}
#>
if ($siteUser. loginname.tostring (). ToUpper (). Contains ($account. ToUpper ())) #判断站点中是否存在该用户
{
"* * * Find account $user, in process ..."
$datetime =get-date
$date = $datetime. ToString (' Yyyy-mm-dd ')
$outInfo = ($datetime. ToString () + "" + $site. Url.tostring () + "setting displayname" + $newname. ToString () + "to $newuser and setting Email: $NEWEM Ail ")
Out-file-filepath $filepath. Txt-inputobject $outInfo-append-encoding UTF8
Try
{
Set-spuser-identity $siteUser-web $site url-displayname $newname-email $NewEmail 2>> $filepath. Txt
}
Catch
{$error [0]. Exception}
}
}
}
“ ”
$site. Dispose ()
}
This article from "Bo shen" blog, reproduced please contact the author!
SharePoint 2013 modifies certain display names, email and Active Directory inconsistencies in the account PowerShell