SharePoint/PnP-JS-Core

Ability to view/add/remove Site Collection Admins?

Closed this issue · 2 comments

Category

[ ] Enhancement

[ ] Bug

[X] Question

Version

Please specify what version of the library you are using: [3.0.9]

Expected / Desired Behavior / Question

Is there any possible way for my application to retrieve/add/remove the users from the Site Collection Admin group? I have tried pnp.sp.site.getRootWeb().then(rootWeb => {}); but I can't seem to find out how to search for this group and get its members.

Thank you very much for your time!

Hey @ken-harris,

This might help:

// Ensure a user on site collection
sp.web.ensureUser('john.doe@contoso.onmicrosoft.com').then(console.log);

// Get site collection admins
sp.web.siteUsers.filter(`IsSiteAdmin eq true`)
    .get().then(console.log);

// Remove a user from site collection admins
sp.web.siteUsers.getByLoginName('i:0#.f|membership|john.doe@contoso.onmicrosoft.com')
    .update({ IsSiteAdmin: false }).then(console.log);

// Add a user to site collection admins
sp.web.siteUsers.getByLoginName('i:0#.f|membership|john.doe@contoso.onmicrosoft.com')
    .update({ IsSiteAdmin: true }).then(console.log);

Thank you for your interest in the sp-pnp-js library. We wanted to mention that this library is being deprecated in July 2018 in favor of the new scoped pnpjs libraries. You should begin transitioning your existing projects when possible or start new projects with the new libraries. Please see the transition guide for more details on migrating and be sure to let us know if you have any questions. Thanks!

That worked perfectly, thank you so much @koltyakov!