1

I'm trying to find a way to remove a user from a group using PnP-SP. My code is as follows:

this.$pnp.sp.web.siteGroups.getById(this.selectedGroup.Id).users
              .remove(user)
              .then(arrResults => {...

The error message is:

t.$pnp.sp.web.siteGroups.getById(...).users.remove is not a function

Any help is greatly appreciated.

1

You can remove the user from SharePoint group using user Id or user login name.

Using User Id:

let userId: number = 1; //replace value with actual user id
this.$pnp.sp.web.siteGroups.getById(this.selectedGroup.Id).users.removeById(userId).then((result) => {
      console.log(result);
})

Using Login Name:

let userLoginName: string = "i:0#.f|membership|user@tenant.onmicrosoft.com"; //replace value with actual user login name
this.$pnp.sp.web.siteGroups.getById(this.selectedGroup.Id).users.removeByLoginName(userLoginName).then((result) => {
      console.log(result);
})
2
  • 1
    Worked like a charm! For some reason there is not a lot of documentation on this topic so thank you very much for your wisdom sir. Nov 5 '21 at 14:19
  • Great, glad it worked for you! Nov 5 '21 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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