Access User Profile Properties from Powershell
By Anatoly Mironov
To use only SPUser objects isn’t always sufficient. To get other properties we have to retrieve user profiles. Giles Hamson gives an example how to get and how to update user profile properties with powershell. Here is an example how to get all work phones:
$url = "http://intranet/"
$site = Get-SPSite $url
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$profiles = $profileManager.GetEnumerator()
while ($profiles.MoveNext()) {
$userProfile = $profiles.Current
$name = $userProfile.DisplayName
$phone = $userProfile\["WorkPhone"\]
$line = '{0};{1}' -f $name, $phone
write $line
}
If you are not sure what properties are called, see the whole list by typing:
$userProfile.Properties | select name
Comments from Wordpress.com
Giles Hamson - Apr 3, 2012
Glad you found the post useful :-) Kind regards Giles
If you update a value, you must do it through “Value”:
$userProfile["WorkPhone"].Value = "46464646"
anilkuchi - Apr 1, 2012
Can you tell me how can i copy the value of one user property to another in SharePoint .We have a custom property called Supervisor which will be entered by the user and i want to copy this property into Manager field in SharePoint , as the organizational profile is not working without manager field . I am writing this in power shell but it is giving me the following error “Unable to index into an object of type Microsoft.Office.Server.UserProfiles.UserProfile.” My Code is $consultantsupername = $userProfile[“ConsultantSupervisor”] $Managername =$userProfile[“Manager”] $userProfile[“ConsultantSupervisor”] = $userProfile[“Manager”] $userProfile.Commit() please help me …Thanks
Naveenkumar - Aug 5, 2013
Hi, can you please tell me how to get the user’s email address in powershell, from list which has a field of “person or group” which allows multiple selection..??
Anatoly Mironov - Aug 1, 2013
Hi, this post is not about list items. But look at this. It should be possible to “translate” this example into PowerShell. http://littletalk.wordpress.com/2010/01/29/get-spuser-object-from-sharepoint-list-item-peoplegroup-picker-field/
Mita - Aug 5, 2014
Hi, Could you please let me know what needs to be done in order to update the user profile properties of the field “WorkPhone” if I want it to have the isReplicable property of it set to false? Thanks