import user profile into UPS

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$site = "http://"
$context = Get-SPServiceContext -Site $site
$web = Get-SPWeb -Identity $site

$upCellPhone = "CellPhone"
$upExtTeleCountryCode = "ExtTeleCountryCode"
$upExtTelInlandPrefix = "ExtTelInlandPrefix"
$upMobTelPrefix = "MobTelPrefix"
$upMobTelNo = "MobTelNo"
$upExtTelLocalNo = "ExtTelLocalNo"
$upWorkPhone = "WorkPhone"
$upExtTelAreaCode = "ExtTelAreaCode"
$upExtFaxLocalNo = "ExtFaxLocalNo"
$upExtFaxAreaCode ="ExtFaxAreaCode"
$upFax = "Fax"
$vTeleNumber =""

$upm = New-Object -TypeName Microsoft.Office.Server.UserProfiles.UserProfileManager -ArgumentList $context
$userslist = Import-Csv -Path .\Profile.csv
for($count=0; $count -lt $userslist.Count; $count++)
{
 #Create User Profile
 $upm.CreateUserProfile($userslist[$count].EmployeeID)
 $upm.Commit()
}

 

#Update Profile Property Values
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$userslist = Import-Csv -Path .\Profile.csv
foreach ($line in $userslist) {

 $up = $profileManager.GetUserProfile($line.adDomainName + "\" + $line.adSAMAccountName)
 $up['EmployeeID'].Value =  $line.EmployeeID
 $up['FirstName'].Value =  $line.givenName
 $up['SPS-PhoneticFirstName'].Value =  $line.KnownAsGivenName
 $up['LastName'].Value =  $line.sn
 $up['SPS-PhoneticLastName'].Value =  $line.KnownAsLastName
 $up['PreferredName'].Value =  $line.DisplayName
 $up['Department'].Value =  $line.department
 $up['Title'].Value =  $line.title
 $up['SPS-JobTitle'].Value =  $line.WorkRole
 
 $up['UserName'].Value = $line.adSAMAccountName
 
 $up['ExtTeleCountryCode'].Value =  $line.ExtTeleCountryCode
 $up['ExtTelAreaCode'].Value =  $line.ExtTelAreaCode
 $up['ExtTelInlandPrefix'].Value =  $line.ExtTelInlandPrefix
 $up['ExtTelLocalNo'].Value =  $line.ExtTelLocalNo
 $up['MobTelPrefix'].Value =  $line.MobTelPrefix
 $up['MobTelNo'].Value =  $line.MobTelNo
 $up['ExtFaxAreaCode'].Value =  $line.ExtFaxAreaCode
 $up['ExtFaxLocalNo'].Value =  $line.ExtFaxLocalNo
 $up['IntFaxLocalNo'].Value =  $line.IntFaxLocalNo
 $up['IntFaxNumber'].Value =  $line.IntFaxNumber
 $up['IntFaxPrefix'].Value =  $line.IntFaxPrefix
 $up['IntTelLocalNo'].Value =  $line.IntTelLocalNo
 $up['IntTelNumber'].Value =  $line.IntTelNumber
 $up['IntTelPrefix'].Value =  $line.IntTelPrefix
 $up['Responsibilities'].Value =  $line.Responsibilities
 $up['Skills'].Value =  $line.Skills
 $up['Interests'].Value =  $line.Interests
 $up['WorkEmail'].Value =  $line.mail
 $up['InternalEmailAddress'].Value =  $line.mailAddress
 $up['Country'].Value =  $line.co
 $up['Company'].Value =  $line.company
 $up['CourtesyTitle'].Value =  $line.personalTitle
 $up['DepartmentNumber'].Value =  $line.departmentNumber
 $up['CountryCode'].Value =  $line.c
 $up['FunctionalManagerID'].Value =  $line.ManagerID
 $up['FunctionalManagerName'].Value =  $line.managerFullName
 $up['LineManagerID'].Value =  $line.LineManagerID
 $up['LineManagerName'].Value =  $line.LineManagerName
 $up['SecretaryID'].Value =  $line.SecretaryEmplID
 $up['OrganizationIdentifier'].Value =  $line.ou
 $up['WorkLocation'].Value =  $line.l
 $up['postalAddress'].Value =  $line.postalAddress
 
 #not sure this line
 $up['ObjectSID-Str-From-SQL'].Value =  $line.StringSID

#Update IsManager
 if ($line.IsLineManager -eq "True")
 { $up['IsLineManager'].Value =  $TRUE
 }
 else
 { $up['IsLineManager'].Value =  $FALSE
 }

 

#Update PictureURL
 $up["PictureURL"].Value = "https://jpg" -f $up["EmployeeID"].Substring(0,4),$up["EmployeeID"]

 

# Update Mobile Number
 if ($up[$upMobTelNo] -ne '' -or $up[$upMobTelNo] -ne $null)
 {
  if ($up[$upExtTelInlandPrefix] -ne '' -or $up[$upExtTelInlandPrefix] -ne $null)
      {
   $up[$upCellPhone].value = "+{0} ({1}) {2} {3}" -f $up[$upExtTeleCountryCode].value,$up[$upExtTelInlandPrefix].value,$up[$upMobTelPrefix].value,$up[$upMobTelNo].value
  }
  else
  {
   $up[$upCellPhone].value = "+{0} {1} {2}" -f $up[$upExtTeleCountryCode].value,$up[$upMobTelPrefix].value,$up[$upMobTelNo].value
  }
  }
 else
 {
  $up[$upCellPhone].Value = ""
 }


# Update Work Phone
 if ($up[$upExtTelLocalNo] -ne '' -or $up[$upExtTelLocalNo] -ne $null)
 {
  $vTeleNumber = "{0}" -f $up[$upExtTelLocalNo]
  #write-host $up[$upExtTelLocalNo].value
  
  if ($up[$upExtTelAreaCode] -ne '' -or $up[$upExtTelAreaCode] -ne $null)
  {
   $vTeleNumber = "{0} {1}" -f $up[$upExtTelAreaCode], $vTeleNumber
  }
  if ($up[$upExtTelInlandPrefix] -ne '' -or $up[$upExtTelInlandPrefix] -ne $null)
  {
   $vTeleNumber = "({0}) {1}" -f $up[$upExtTelInlandPrefix], $vTeleNumber
  }
  if ($up[$upExtTeleCountryCode] -ne '' -or $up[$upExtTeleCountryCode] -ne $null)
  {
   $vTeleNumber = "+{0} {1}" -f $up[$upExtTeleCountryCode], $vTeleNumber
  }
  
  $up[$upWorkPhone].Value = $vTeleNumber
  
    }
 else
 {
  $up[$upWorkPhone].Value = ""
 }


# Update External Fax Number
 if ($up[$upExtFaxLocalNo] -ne '' -or $up[$upExtFaxLocalNo] -ne $null)
 {
  if ($up[$upExtTelInlandPrefix] -ne '' -or $up[$upExtTelInlandPrefix] -ne $null)
      {
   $up[$upFax].value = "+{0} ({1}) {2} {3}" -f $up[$upExtTeleCountryCode].value,$up[$upExtTelInlandPrefix].value,$up[$upExtFaxAreaCode].value,$up[$upExtFaxLocalNo].value
  }
  else
  {
   $up[$upFax].value = "+{0} {1} {2}" -f $up[$upExtTeleCountryCode].value,$up[$upExtFaxAreaCode].value, $up[$upExtFaxLocalNo].value
  }
  }
 else
 {
  $up[$upFax].Value = ""
 }
 $up.Commit()
}

 

 

 

 

 

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值