Get-spuser-web Http://wfe1 | FL (view accounts in this site collection)
$user = Get-spuser-web http://wfe1-Identity 18 (the account with ID 18 is assigned the variable $user, the following statement will fail without the variable, and 18 can be replaced with the user name)
Move-spuser-ignoresid-identity $user-newalias ' test\sale02 ' (migrate the account to a new account, either in the same domain or in a different domain)
This action will take effect at all site levels under Web application
---------------------------------------------------------------------
If the above cannot take effect on all site collections, you can modify the migration with the following code:(not recommended)
#该脚本只做用户迁移, can not do group migration, if you want to do group migration, the script to change the loginname displayname can be;
Add-pssnapin Microsoft.SharePoint.PowerShell
$ConfirmPreference = ' None ' #关闭确认提示
$filePath = "C:\file\"
$allUsers =get-content C:\file\user.txt-Encoding UTF8 #从文件中读取需要迁移的账户, each line contains an old account, a new account and a new email address, separated by---between fields
$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)
{
$oldUser = ($user. ToString ()-split "---") [0]
$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 ($oldUser. ToUpper ())) #判断站点中是否存在该用户
{
"* * * Find account $user, in process ..."
$datetime =get-date
$date = $datetime. ToString (' Yyyy-mm-dd ')
$outInfo = ($datetime. ToString () + "" + $site. Url.tostring () + "moving" + $siteUser. Loginname.tostring () + "to $newuser and Setting Email: $newemai L ")
Out-file-filepath $filepath. Txt-inputobject $outInfo-append-encoding UTF8
Set-spuser-identity $siteUser-web $site. Url-email $NewEmail 2>> $filepath. Txt
#set-spuser-identity $siteUser-web $site url-syncfromad 2>> $filepath. Txt
$siteuser 1=get-spuser-web $site. url.tostring ()-identity $siteUser
$FullUserLogin = $userPrefix + "|" + $NewUser
Try
{
Move-spuser-identity $siteUser 1-newalias $newUser-ignoresid 2>> $filepath. TXT #move account must use the preceding statement to assign the account get out to the variable, before you can call the variable user in the Move statement otherwise error
}
Catch
{$error [0]. Exception}
}
}
}
“ ”
$site. Dispose ()
}
This article from "Bo shen" blog, reproduced please contact the author!
SharePoint 2013: Move user PowerShell in SharePoint after Active Directory migration user