Zhaobab
3/30/2015 - 12:12 PM

Set property to every User Profiles (UPS).

Set property to every User Profiles (UPS).

<config>
	<MySiteUrl>http://rbla-sp2010-002/my/</MySiteUrl>
	<users>
		<user name="rbla\rbla" />
		<user name="rbla\jdiouf" />
		<user name="rbla\ftri" />
	</users>
</config>
# ----------------------------------------------
# Author: Romain Blanchard
# Date: 23.04.2013
# Description: Set property to every User Profiles (UPS).
# ----------------------------------------------

# -- Initialize --#
$xmlinput = [xml] (Get-Content "name.xml")
$siteurl = $xmlinput.Config.MySiteUrl
$mySiteHostSite = Get-SPSite $siteurl
$mySiteHostWeb = $mySiteHostSite.OpenWeb()
$context = Get-SPServiceContext $mySiteHostSite
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$count = 0

# -- Script -- #
Select-Xml -Path "name.xml" -Xpath "/config/users/user" | ForEach-Object { 
$fullname = $_.Node.name

	if ($profileManager.UserExists($fullname))
	{
		$up = $profileManager.GetUserProfile($fullname)
		$up["SPS-Responsibility"].Value = "Energy in Motion"
		$up.Commit()
		$count++
		write-host $fullname"'s property has been modified!" -foregroundColor Green
	}
	else
	{
		write-host $fullname "profile cannot be found!" -foregroundcolor Red
	}	
}

write-host ""
write-host "-------------------------------------"
write-host "$count users profile has been modified!" -foregroundColor Green
write-host "-------------------------------------"