-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathremove_user_from_group.py
More file actions
30 lines (21 loc) · 983 Bytes
/
Copy pathremove_user_from_group.py
File metadata and controls
30 lines (21 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
Remove a user from a SharePoint site group.
Requires Site Owner.
https://learn.microsoft.com/en-us/sharepoint/dev/apis/rest-api/csom/group
"""
import argparse
from office365.sharepoint.client_context import ClientContext
from tests.settings import client_id, password, site_url, tenant, user_principal, username
def main():
parser = argparse.ArgumentParser(description="Remove a user from a site group")
parser.add_argument("--group", default="Team Site Members", help="group name")
parser.add_argument("--user", default=user_principal, help="user login/UPN")
args = parser.parse_args()
ctx = ClientContext(site_url).with_username_and_password(
tenant=tenant, client_id=client_id, username=username, password=password
)
group = ctx.web.site_groups.get_by_name(args.group)
group.users.remove_by_login_name(args.user).execute_query()
print(f"User removed from '{args.group}': {args.user}")
if __name__ == "__main__":
main()