-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathdeactivate_feature.py
More file actions
33 lines (23 loc) · 1.17 KB
/
Copy pathdeactivate_feature.py
File metadata and controls
33 lines (23 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
"""Demonstrates how to deactivate a site feature.
Official documentation: https://learn.microsoft.com/en-us/sharepoint/dev/apis/rest-api/csom/features
"""
import argparse
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.features.definitions.scope import FeatureDefinitionScope
from office365.sharepoint.features.known_list import KnownFeaturesList
from tests.settings import cert_path, cert_thumbprint, client_id, site_url, tenant
def main():
parser = argparse.ArgumentParser(description="Deactivate a site feature")
parser.add_argument("--site-url", default=site_url, help="target site URL")
args = parser.parse_args()
ctx = ClientContext(args.site_url).with_client_certificate(
tenant, client_id=client_id, thumbprint=cert_thumbprint, cert_path=cert_path
)
# Activate a feature first, then deactivate it
f = ctx.site.features.add(KnownFeaturesList.ContentTypeHub, False, FeatureDefinitionScope.Farm).execute_query()
print(f"Activated: {f.display_name}")
# Deactivate (remove) the feature
f.delete_object().execute_query()
print(f"Deactivated: {f.display_name}")
if __name__ == "__main__":
main()