1

I'm using powershell to get some data from userprofile but I cant get to display the Managers field name as its a person field. What I currently get it domain\username . How can I get a display name .

   $Manager = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::Manager].Value

Above is how Im currently getting the Managers field.

Thanks in Advance

1 Answer 1

3

Try the below code, use the domain\username of the Manager and get the userprofile object of the Manager. From that you will be able to get all the details you require

$site=new-object Microsoft.SharePoint.SPSite("https://c05470sp10:7443");            
$serviceContext = Get-SPServiceContext $site;            
$site.Dispose();            
$upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);            
$userProfile = $upm.GetUserProfile("company\accountid");
$userProfileManager = $upm.GetUserProfile($userProfile["Manager"].Value);
$userProfileManager["Name"].Value

Reference: http://social.technet.microsoft.com/wiki/contents/articles/20692.sharepoint-2013-get-set-and-copy-user-profile-properties-using-powershell.aspx

2
  • Thanks Nagarajan but its not working.I'm getting value cannot be null despite hard coding "company\accountid"
    – naijacoder
    Commented Oct 21, 2015 at 3:54
  • Tried email address as suggested in the reference but getting error - something wrong with retrieving the user profile
    – naijacoder
    Commented Oct 21, 2015 at 5:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.