How to add user to specific group in Office 365 ?

SPUser user1 = web.AllUsers["i:0#.f|membership|admin@test.onmicrosoft.com"];
web.SiteGroups["Team Site Members"].AddUser(user1);
//oeGroup.AddUser(user1.LoginName, user1.Email, user1.Name, user1.Notes);
//oeGroup.Users.Add(user1.LoginName, user1.Email, user1.Name, user1.Notes);

this is the code I used to add user but it give me a error

The user does not exist or is not unique.


Like this:

Add-SPOUser -Site https://contoso.sharepoint.com -LoginName melissa.kerr@contoso.com -Group "Team Site Members"

Ref: Add-SPOUser

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.