Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Tenant Administration

Manage SharePoint tenant settings, sites, admins, sharing, and licensing. These examples use the tenant admin API via the tenant admin site (https://contoso-admin.sharepoint.com).


Prerequisites

Requirement Description Reference
SharePoint Administrator or Global Administrator role Required for all tenant-level operations. Connection to the tenant admin site (-admin.sharepoint.com). SharePoint admin roles

A Tenant object is the entry point for all tenant-level operations.


Examples

Configure settings

Step Operation File Required role API reference
1 Allow or block custom script on sites allow_custom_script.py SharePoint Admin Tenant REST API
2 Change tenant sharing capability change_sharing_capability.py SharePoint Admin Tenant REST API
3 Enable app-only authentication (legacy) enable_app_only_authentication.py SharePoint Admin Tenant REST API
4 Check if legacy auth is enabled is_legacy_auth_enabled.py SharePoint Admin Tenant REST API

Browse and discover

Step Operation File Required role API reference
5 List all site collections get_all_sites.py SharePoint Admin Tenant REST API
6 List my sites get_my_sites.py SharePoint Admin Tenant REST API
7 Get a site by URL get_site.py SharePoint Admin Tenant REST API
8 List home sites get_home_sites.py SharePoint Admin Tenant REST API
9 Find sites without a Microsoft 365 group sites_without_a_group.py SharePoint Admin Tenant REST API

Manage admins

Step Operation File Required role API reference
10 Get site collection admin get_site_admin.py SharePoint Admin Tenant REST API
11 Set site collection admin set_site_admin.py SharePoint Admin Tenant REST API
12 Delete site collections delete_sites.py SharePoint Admin Tenant REST API

Reports and settings

Step Operation File Required role API reference
13 Check user license assignments check_licenses.py SharePoint Admin Tenant REST API
14 Export all tenant settings to file export_tenant_settings.py SharePoint Admin Tenant REST API
15 Print tenant settings print_tenant_settings.py SharePoint Admin Tenant REST API
16 Add a tenant theme add_tenant_theme.py SharePoint Admin Tenant REST API
17 Print server settings print_server_settings.py SharePoint Admin Tenant REST API

Storage & resource reporting

Step Operation File Required role API reference
18 Storage usage report (all sites) site_storage_report.py SharePoint Admin + Sites.Read.All Tenant REST API
19 Find orphan OneDrive sites find_orphan_onedrives.py SharePoint Admin + Directory.Read.All Tenant REST API

Quick start

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.tenant.administration.tenant import Tenant

ctx = ClientContext("https://contoso-admin.sharepoint.com").with_client_secret(
    "contoso.onmicrosoft.com", "client_id", "client_secret"
)

tenant = Tenant(ctx)
sites = tenant.get_site_properties_from_sharepoint().execute_query()
for site in sites:
    print(f"  {site.Url}  ({site.Title})")

API reference