457475451 发表于 2018-9-1 13:20:53

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 "---" )
  $newname=($user.tostring() -split "---" )
  $NewEmail=($user.tostring() -split "---" )
  
  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 $NewEmail2>>$filepath$date.TXT
  }
  catch
  {$error.Exception}
  }
  }
  }
  “ ”
  $site.dispose()
  }

页: [1]
查看完整版本: sharepoint 2013 修改某些显示名,email和活动目录不一致的账户 powershell