I have a question regarding SharePoint development. I'm working on a SPFX webpart for SP2019, the webpart is going to retrieve data from external source and the data will contain AD users. In my webpart I would like to show the Name of the user instead of his AD account. How can I achieve that exactly?

So the value that I get is domain\username.

I got so far that I can get the user display name with pnp js sp.web.siteusers and loginame like so "i:0#.w|domain\username" , so it is basically from _api/web/siteusers. BUT the problem is, that ofcourse I do not see all the users there that are in AD.

For example, I know that user has rights to access the site, but he never visited it, so I could not find his login in siteusers.

I tried as well the sp.web.ensureuser() but the thing i have to pass is a bit different what I have... and again it says that it will add the user to the web, what is not really needed as wel. I just need to get the name.

So how exactly, can I then get the name of the user or a group?


1 Answer 1


I believe you can use @pnp/sp/profiles

Gets properties for a specified user

const loginName = "i:0#.f|membership|[email protected]";
const profile = await sp.profiles.getPropertiesFor(loginName);

// Properties are stored in inconvenient Key/Value pairs,
// so parse into an object called userProperties
var props = {};
profile.UserProfileProperties.forEach((prop) => {
  props[prop.Key] = prop.Value;

profile.userProperties = props;
console.log("Account Name: " + profile.userProperties.AccountName);
  • yes that is what I thought as wel, but the loginname... i don't have it in that kind of format, for example I don't get the email of the user i only have his login name in format domain\username... what to do then?
    – Shkipper
    Jun 2, 2021 at 6:09
  • I think you need to convert the format of loginname by substring or split functions.
    – Mark L
    Jun 2, 2021 at 6:19
  • so even if it is not online, it has to be membership|[email protected], :/
    – Shkipper
    Jun 2, 2021 at 11:39
  • Yes, indeed the user name I can retrieve like that but ... what to do with the AD Group? how to manage that? Or how to verify it?
    – Shkipper
    Jun 2, 2021 at 12:42

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.