-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathadd_remove.py
More file actions
34 lines (24 loc) · 1.17 KB
/
Copy pathadd_remove.py
File metadata and controls
34 lines (24 loc) · 1.17 KB
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
31
32
33
34
"""
Create a new SharePoint site group (removed after the demo unless --keep).
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, username
def main():
parser = argparse.ArgumentParser(description="Create a site group")
parser.add_argument("--name", default="Project Contributors", help="group name")
parser.add_argument("--description", default="Contributors to project sites", help="group description")
parser.add_argument("--keep", action="store_true", help="keep the group (default: delete after demo)")
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.add(args.name, args.description).execute_query()
print(f"Group created: {group.title} (ID: {group.id})")
if not args.keep:
group.delete_object().execute_query()
print(" (group removed after demo)")
if __name__ == "__main__":
main()