The two most widely used user profile property types in SharePoint 2010 are “string (Single Value)” and “string (Multi Value)”. Single value property types work in a similar way to “Single line of text” columns in lists and libraries – examples being Name, Department, Job Type, etc. Multi value property types use the Managed Metadata service to allow the multiple input of new or previously used values from the Keywords term set – examples being Skills, Schools, Responsibilities, etc.
The PowerShell script below provides an example of how to add or modify a single value user profile property for an individual user. Admittedly, this can be done quite easily by using the Central Administration UI (although it does take a few clicks), but it’s real power is when you combine the script with a CSV or XML file to bulk change hundreds of user profile properties in a matter of seconds – you can find examples of using CSV and XML files for bulk operations here and here, although I plan to publish more articles on these techniques in future posts.
Note: The user running the script (which I assume is some sort of SharePoint Administrator) must have been granted the Manage Profiles right in the Administrators section and Full Control rights in the Permissions section of the User Profile Service Application (pictured below).
The script below changes the value of the Web Site attribute for a user with the account name DOMAIN\Phil.Childs. You will need to specify the My Site host site collection URL for the $mySiteUrl variable:
#Set up default variables
$mySiteUrl = "http://mysite"
$adAccount = "DOMAIN\phil.childs"
$upAttribute = "WebSite"
$upAttributeValue = “http://get-spscripts.com”
#Get site objects and connect to User Profile Manager service
$site = Get-SPSite $mySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
#Check to see if user profile exists
#Get user profile and change the value
$up = $profileManager.GetUserProfile($adAccount)
$up[$upAttribute].Value = $upAttributeValue
write-host "Profile for user"$adAccount "cannot be found"
#Dispose of site object
In a future post I will run through how to use a similar approach to change a multi value user profile property…