
[SPS] Update multiple UPA properties using a CSV file
This script will help you update multiple User Profile Service Application fields using a CSV file as input:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#First load the SharePoint commands add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Set up the job variables $csvfile="c:\temp\usersATTR.csv" $mySiteUrl = "http://pbnet-sps:9091/" #$upAttribute = "Title" #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 U if ($profileManager.UserExists($line.NTName)) { #Get user profile and change the value $up = $profileManager.GetUserProfile($line.NTName) $up[$line.PropertyName].Value = $line.PropertyVal $up.Commit() } else { write-host "Profile for user"$line.NTName "cannot be found" } } #Dispose of site object $site.Dispose() |
The input CSV file looks […]