PnP JS to add or remove user from SharePoint Group

Hello.

Is there a way to leverage PnP JS to add or remove a user from a SharePoint Group called "Admins" for example via an add/remove user button?

Thanks,
stormanh

Hello @stormanh,

You can use the code below to add user to SharePoint group:

    pnp.sp.web.siteGroups.getByName("Main Members").users
    .add("i:0#.f|membership|jdoe@domainame.onmicrosoft.com").then(function(d){
        console.log('done')
    });

Thank you @mnikitina!

1 Like

Hi, I have 4 specific sharepoint groups and I would like to add a member of my azure to one of them via a function, once it is found by the Picker. how can I do?

private async _addusertogroup(groupName: string, userName:string[]) {

sp.web.siteGroups.getByName(groupName).users

.add("i:0#.f|membership|diego.maradona@giannibernaudo.onmicrosoft.com")

.then(function(result){

    console.log(result)

})

}

the function is passed on the click of a button fabric ui