Wednesday, September 25, 2013

SharePoint 2010 - Update People Profiles Telephone Numbers With Powershell

A task was assigned to me to update 5000 telephone numbers in SharePoint..... easiest method to script and read from CSV - as so .....


Input file format (CSV) - Important note the headers have to be exactly whats in script

ntname,number
domain\smith,898021889
domain\brown,78798798

Script to read through and update WorkPhone 

#First load the SharePoint commands 
#add-PSSnapIn Microsoft.SharePoint.PowerShell

#Set up the job variables 
$csvfile="TelephoneNumbers.csv" 
$mySiteUrl = "<mysiteurl>
$upAttribute = "WorkPhone"

#Connect to User Profile Manager service 
$site = Get-SPSite $mySiteUrl 
$context = Get-SPServiceContext $site 
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) 

#Create Lists from each item in CSV file 
$csvData = Import-Csv $csvfile 

#Now iterate through the list to update the attribute with new value 
foreach ($line in $csvData)

    #Check to see if user profile exists 
    if ($profileManager.UserExists($line.NTName)) 
        { 
            #Get user profile and change the value 
            $up = $profileManager.GetUserProfile($line.NTName) 
 #           $up[$upAttribute].Value = $line.PropertyVal 
  $up[$upAttribute].Value = $line.number
            $up.Commit() 
        } 
    else 
    { 
        write-host "Profile for user"$line.NTName "cannot be found" 
    } 


#Dispose of site object 
$site.Dispose()

No comments:

Post a Comment