Manage SharePoint site groups — create, list, find, add and remove members.
| Requirement | Description | Reference |
|---|---|---|
| Site Owner role | Required to create, delete, and manage group membership. | SharePoint admin roles |
| Step | Operation | File | Required role | API reference |
|---|---|---|---|---|
| 1 | List — enumerate all site groups | list_groups.py |
Read access | Group collection |
| 2 | Get by name — retrieve a group by its name | get_by_name.py |
Read access | Get by name |
| 3 | Add — create a new site group | add_remove.py |
Site Owner | Create |
| 4 | Add user — add a member to a group | add_user_to_group.py |
Site Owner | Add user |
| 5 | Remove user — remove a member from a group | remove_user_from_group.py |
Site Owner | Remove user |
| 6 | Expand — list group members with details | expand_to_principals.py |
Read access | Expand to principals |
from office365.sharepoint.client_context import ClientContext
ctx = ClientContext("https://contoso.sharepoint.com/sites/team").with_client_secret(
"contoso.onmicrosoft.com", "client_id", "client_secret"
)
# List all site groups
groups = ctx.web.site_groups.get().execute_query()
for g in groups:
print(f" {g.title} (ID: {g.id})")