码迷,mamicode.com
首页 > 其他好文 > 详细

用powershell批量新增user profile

时间:2014-06-10 16:09:30      阅读:305      评论:0      收藏:0      [点我收藏+]

标签:style   tar   ext   color   get   strong   

 SharePoint 2013 新系统,要在User Profile Service里把人全加一下,其实同步ad更方便,但ad里的人太多,没必要全要,只要大中华区就行了,问hr要了一份人员名单,写了个脚本

 

先来个xml,把要加的人ad账号列一下

<Users>
  <UserName Name="user_a" />
  <UserName Name="user_b" />
  <UserName Name="user_c" />
  <UserName Name="user_d" />
  <UserName Name="user_e" />
  <UserName Name="user_f" />

</Users>

 

再来一段简单的脚本

 

#********************************************************************
# Create New User
#
#********************************************************************

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell‘}
if ($snapin -eq $null)
{
  Write-Host "Loading SharePoint Powershell Snapin..."
  Add-PSSnapin "Microsoft.SharePoint.Powershell"
  Write-Host "SharePoint Powershell Snapin Loaded"
}
# Get XML Configuration file
[xml]$xmlData=Get-Content "C:\\test.xml"

Write-host ""
Write-host -f Yellow "Starting create new user"

# create a connection to the User Profile Manager
$MySite = Get-SPSite <siteUrl>
$context = Get-SPServiceContext $MySite

# Get UserProfileManager Object
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

$xmlData.Users.UserName | ForEach-Object {

  if($profileManager.UserExists($_.Name) -eq $false){
    $profileManager.CreateUserProfile($_.Name)
    Write-host -f Green $_.Name"created"
  }

  else{
    Write-host -f Red $_.Name"already exist"
  }

}

用powershell批量新增user profile,布布扣,bubuko.com

用powershell批量新增user profile

标签:style   tar   ext   color   get   strong   

原文地址:http://www.cnblogs.com/graccc/p/3779587.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!