I have a CSOM Script (Below) that I am using to delete a user from a SharePoint Group. But in some of the site the users are added directly to the site.
Can you please let me know, how I can remove a user who is not part of any Group?
I have to run this on each Sub Site in a site collection.
ClientContext clientContext = new ClientContext(siteUrl);
Web web = clientContext.Web;
GroupCreationInformation groupCreationInfo = new GroupCreationInformation();
groupCreationInfo.Title = "Custom Group";
groupCreationInfo.Description="Custom group created using Client Object Model";
User owner = web.EnsureUser(@"domainName\ownerName");
User member = web.EnsureUser(@"domainName\userName");
Group group = web.SiteGroups.Add(groupCreationInfo);
group.Owner = owner;
group.Users.RemoveUser(member);
group.Update();
clientContext.ExecuteQuery();