Skip to content

Latest commit

 

History

History
90 lines (65 loc) · 5.88 KB

File metadata and controls

90 lines (65 loc) · 5.88 KB

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

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

Browse and discover

Operation File Required role API reference
List all site collections get_all_sites.py SharePoint Admin Tenant REST API
List my sites (via search) get_my_sites.py SharePoint Admin Tenant REST API
Get a site by URL get_site.py SharePoint Admin Tenant REST API
List home sites get_home_sites.py SharePoint Admin Tenant REST API
Find sites without a Microsoft 365 group sites_without_a_group.py SharePoint Admin Tenant REST API

Manage admins and sites

Operation File Required role API reference
Get site collection admins get_site_admin.py SharePoint Admin Tenant REST API
Set site collection admins set_site_admin.py SharePoint Admin Tenant REST API
Delete site collections delete_sites.py SharePoint Admin Tenant REST API
List / restore deleted sites restore_deleted_site.py SharePoint Admin Tenant REST API

Reports and settings

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

Storage & resource reporting

Operation File Required role API reference
File version policy (read / set / clear) file_version_policy.py SharePoint Admin + Sites.FullControl.All Tenant REST API
Storage usage report (all sites) site_storage_report.py SharePoint Admin + Sites.Read.All Tenant REST API
Quota management (site + OneDrive) quota_management.py SharePoint Admin + Sites.FullControl.All Tenant REST API
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