首页 > 代码库 > sharepoint 2013 修改某些显示名,email和活动目录不一致的账户 powershell
sharepoint 2013 修改某些显示名,email和活动目录不一致的账户 powershell
#该脚本修改某些显示名,email和活动目录不一致的账户
Add-PSSnapin Microsoft.SharePoint.PowerShell
$ConfirmPreference = ‘None‘ #关闭确认提示
$filePath="c:\file\"
$allUsers=get-content C:\file\user.txt -Encoding UTF8 #从文件中读取需要迁移的账户,每一行包含账户和新的显示名称,新的email地址,字段之间用---隔开
$webApp=get-spwebapplication "http://wfe1.test.com" #设置需要修改的web application
$allSites= $webApp.sites
foreach ($site in $allSites)
{
"正在查询$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())) #判断站点中是否存在该用户
{
“ ***找到账户$user,正在处理中......”
$datetime=get-date
$date=$datetime.ToString(‘yyyy-MM-dd‘)
$outInfo=($datetime.ToString() +" "+$site.url.ToString() + " setting displayname "+$newname.tostring() +" To $newuser and Setting Email:$newemail")
Out-File -filePath $filepath$date.TXT -inputobject $outInfo -Append -Encoding UTF8
try
{
set-spuser -Identity $siteUser -web $site.url -DisplayName $newname -Email $NewEmail 2>>$filepath$date.TXT
}
catch
{$error[0].Exception}
}
}
}
“ ”
$site.dispose()
}
本文出自 “博深” 博客,转载请与作者联系!
sharepoint 2013 修改某些显示名,email和活动目录不一致的账户 powershell