private object GetUserInformation(string userPrincipalName) { var peopleContext = new Microsoft.SharePoint.Client.UserProfiles.PeopleManager(ClientContext); var personProperties = peopleContext.GetPropertiesFor(userPrincipalName); ClientContext.Load(personProperties); ClientContext.ExecuteQuery(); if (personProperties != null) { LogVerbose("Tenant PeopleManager"); var profileProperties = personProperties.UserProfileProperties.ToList(); LogVerbose("Display Name: {0}", personProperties.DisplayName); LogVerbose("Email {0}", personProperties.Email); LogVerbose("Latest Post {0}", personProperties.LatestPost); LogVerbose("Personal Url {0}", personProperties.PersonalUrl); LogVerbose("UserProfile_GUID: {0}", GetPropertyValue(profileProperties, "UserProfile_GUID")); LogVerbose("SPS-DistinguisedName: {0}", GetPropertyValue(profileProperties, "SPS-DistinguishedName")); LogVerbose("SID: {0}", GetPropertyValue(profileProperties, "SID")); LogVerbose("msOnline-ObjectId: {0}", GetPropertyValue(profileProperties, "msOnline-ObjectId")); profileProperties.ForEach(f => { LogVerbose("Property:{0} with value:{1}", f.Key, f.Value); }); } return(null); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); var models = new List <SPUserDefinitionModel>(); try { LogVerbose("Querying UserProfiles.PeopleManager"); var userPrincipalName = string.Format("i:0#.f|membership|{0}", this.UserName); var peopleContext = new Microsoft.SharePoint.Client.UserProfiles.PeopleManager(this.ClientContext); var personProperties = peopleContext.GetPropertiesFor(userPrincipalName); this.ClientContext.Load(personProperties); this.ClientContext.ExecuteQuery(); if (personProperties != null) { var profileProperties = personProperties.UserProfileProperties.ToList(); LogVerbose("Display Name: {0}", personProperties.DisplayName); var model = new SPUserDefinitionModel() { UserDisplay = personProperties.DisplayName, UserEmail = personProperties.Email, LatestPost = personProperties.LatestPost, OD4BUrl = personProperties.PersonalUrl, UserProfileGUID = profileProperties.GetPropertyValue("UserProfile_GUID"), SPSDistinguishedName = profileProperties.GetPropertyValue("SPS-DistinguishedName"), SPSSid = profileProperties.GetPropertyValue("SID"), MSOnlineObjectId = profileProperties.GetPropertyValue("msOnline-ObjectId") }; models.Add(model); } models.ForEach(user => WriteObject(user)); } catch (Exception ex) { LogError(ex, "Failed to execute QueryUserProfile in tenant {0}", this.ClientContext.Url); } }