使用powershell修改sharepoint 2013中某些显示名,email和活动目录不一致的账户

2017年10月11日讲师:林老师浏览:6479次

Add-PSSnapin Microsoft.SharePoint.PowerShell $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.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() }
分享 0

您已经赞过了!