SharePoint 2013 modifies certain display names, email and Active Directory inconsistencies in the account PowerShell

Source: Internet
Author: User

#该脚本修改某些显示名, 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.