-
-
Notifications
You must be signed in to change notification settings - Fork 371
Expand file tree
/
Copy pathset_profile_property.py
More file actions
51 lines (39 loc) · 1.96 KB
/
Copy pathset_profile_property.py
File metadata and controls
51 lines (39 loc) · 1.96 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Set a user profile property (single- or multi-valued).
Example property names: ``SPS-Skills`` (multi-valued), ``SPS-Location``,
``AboutMe``, ``Department``.
https://learn.microsoft.com/en-us/sharepoint/dev/apis/people-rest-api
"""
import argparse
from office365.sharepoint.client_context import ClientContext
from tests.settings import cert_path, cert_thumbprint, client_id, site_url, tenant
def main():
parser = argparse.ArgumentParser(description="Set a user profile property")
parser.add_argument("--user", default=None, help="Account name of the user (default: current user)")
parser.add_argument("--property", required=True, help="Profile property name, e.g. SPS-Skills")
parser.add_argument("--value", help="Value for a single-valued property")
parser.add_argument("--values", nargs="+", help="Values for a multi-valued property")
parser.add_argument("--commit", action="store_true", help="Actually commit (default: dry-run)")
args = parser.parse_args()
if not args.value and not args.values:
raise SystemExit("Provide --value (single) or --values (multi)")
ctx = ClientContext(site_url).with_client_certificate(
tenant, client_id=client_id, thumbprint=cert_thumbprint, cert_path=cert_path
)
account_name = args.user
if not account_name:
me = ctx.web.current_user
account_name = me.login_name
if not account_name:
raise SystemExit("Account name could not be resolved")
if not args.commit:
print(f"[dry-run] would set '{args.property}' = {args.value or args.values} on {account_name}")
return
if args.values:
ctx.people_manager.set_multi_valued_profile_property(account_name, args.property, args.values)
else:
ctx.people_manager.set_single_value_profile_property(account_name, args.property, args.value)
ctx.execute_query()
print(f"Set '{args.property}' = {args.value or args.values} on {account_name}")
if __name__ == "__main__":
main()