How to Add an User to a SharePoint Group using CSOM

This script allows to add a user to an existing SharePoint Group in a SharePoint site. The script defines a function where the Client Side Object Model (CSOM) is used to add the user to the SharePoint Group. In order to be able to add a user to a group, you have to use the right

5 Star
1,221 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • sUserToAdd
    4 Posts | Last post September 24, 2018
    • Trying to understand this field. It looks like it's and Active Directory user.
      Can we add an outside user? Like an email address?
      Can you expand on the formatting for this field?
    • Ey Sam,
      The format is that one because this script Works for SharePoint OnPremises and there you have claims authentication so you have to specify the user in that way. For SPO you will need to use the following format: "i:0#.f|membership|<Office365_UserAccount>"
    • Hola,
      FYI : Just tested the script on my test SPO with $sUserToAdd="" and it worked like a charm.
      By the way, big thanks Juan Carlos for the clean script.
    • Ey Sam,
      As Seb has said, the script should also work with small modifications in a SPO environment. By the way, the format you see in $sUSerToAdd for a user account is just how SharePoint deal with it internally...similar format applies if you are not using AD users and you are using a DB user.