PowerShell script to update user profile properties

Posted on 7/4/2013 @ 12:35 PM in #SharePoint by | Feedback | 4917 views

Title says it all, here is the script,

   1:  $csvfile="users.csv" 
   2:  $mySiteUrl = "enteryourmysiteurlhere" 
   3:  $upAttribute = "attributeToUpdate" 
   4:  $site = Get-SPSite $mySiteUrl 
   5:  $context = Get-SPServiceContext $site 
   6:  $profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) 
   7:  $csvData = Import-Csv $csvfile 
   8:  foreach ($line in $csvData)
   9:  { 
  10:      if ($profileManager.UserExists($line.username)) 
  11:          { 
  12:              $up = $profileManager.GetUserProfile($line.username) 
  13:              $up[$upAttribute].Value = $line.attributeval 
  14:              $up.Commit() 
  15:          } 
  16:      else 
  17:      { 
  18:          write-host $line.username " profile not found" 
  19:      } 
  20:  } 
  21:  $site.Dispose()

Sound off but keep it civil:

Older comments..