|
81bf4b5d
»
|
glenc |
2008-05-18 |
Updated script to use named... |
1 |
# setprofileprop.py |
| |
2 |
""" |
| |
3 |
Set Profile Property |
| |
4 |
This script will set a property on all user profiles based on the pattern provided. |
| |
5 |
|
| |
6 |
Usage: |
| |
7 |
|
| |
8 |
ipy setprofileprop.py --url http://myserver --prop Picture |
| |
9 |
--value http://myserver/pics/{Alias}.jpg |
| |
10 |
|
| |
11 |
Arguments: |
| |
12 |
|
| |
13 |
url - server url |
| |
14 |
prop - property to set |
| |
15 |
value - value to set the property to |
| |
16 |
[--help] - show this help |
| |
17 |
|
| |
18 |
""" |
|
9609002e
»
|
glenc |
2008-05-17 |
Started script for setting ... |
19 |
|
| |
20 |
import sp |
| |
21 |
from sp import sharedservices |
|
c238dfcf
»
|
glenc |
2008-05-18 |
Added new scriptutil module... |
22 |
import re |
| |
23 |
import sys |
| |
24 |
import scriptutil |
|
9609002e
»
|
glenc |
2008-05-17 |
Started script for setting ... |
25 |
|
|
5e914f46
»
|
glenc |
2008-05-18 |
Cleanup on scripts |
26 |
__all__ = ["set_profile_prop"] |
| |
27 |
|
|
81bf4b5d
»
|
glenc |
2008-05-18 |
Updated script to use named... |
28 |
def main(argv): |
|
c238dfcf
»
|
glenc |
2008-05-18 |
Added new scriptutil module... |
29 |
args = scriptutil.getargs(argv, ["url=", "prop=", "value="], [], __doc__, True) |
| |
30 |
set_profile_prop(args["url"], args["prop"], args["value"]) |
|
81bf4b5d
»
|
glenc |
2008-05-18 |
Updated script to use named... |
31 |
|
| |
32 |
|
|
5e914f46
»
|
glenc |
2008-05-18 |
Cleanup on scripts |
33 |
def set_profile_prop(url, prop, value): |
|
9609002e
»
|
glenc |
2008-05-17 |
Started script for setting ... |
34 |
"""Executes the script""" |
| |
35 |
|
|
f09035b3
»
|
glenc |
2008-05-17 |
Finished script to set prof... |
36 |
# walk over all profiles and call apply_value |
|
5e914f46
»
|
glenc |
2008-05-18 |
Cleanup on scripts |
37 |
sharedservices.enum_profiles(url, lambda p: _apply_value(p, prop, value)) |
|
9609002e
»
|
glenc |
2008-05-17 |
Started script for setting ... |
38 |
|
| |
39 |
|
|
5e914f46
»
|
glenc |
2008-05-18 |
Cleanup on scripts |
40 |
def _apply_value(profile, prop, value): |
|
f09035b3
»
|
glenc |
2008-05-17 |
Finished script to set prof... |
41 |
"""Applies the value to the profile provided""" |
|
9609002e
»
|
glenc |
2008-05-17 |
Started script for setting ... |
42 |
|
|
5e914f46
»
|
glenc |
2008-05-18 |
Cleanup on scripts |
43 |
print "Processing", profile["AccountName"] |
| |
44 |
|
|
f09035b3
»
|
glenc |
2008-05-17 |
Finished script to set prof... |
45 |
# take the value, locate any {key} patterns, then |
|
9609002e
»
|
glenc |
2008-05-17 |
Started script for setting ... |
46 |
# replace each with the property from the profile |
| |
47 |
regex = re.compile("{(.*?)}") |
|
f09035b3
»
|
glenc |
2008-05-17 |
Finished script to set prof... |
48 |
for match in regex.finditer(value): |
|
9609002e
»
|
glenc |
2008-05-17 |
Started script for setting ... |
49 |
key = match.group(1) |
|
f09035b3
»
|
glenc |
2008-05-17 |
Finished script to set prof... |
50 |
|
| |
51 |
# handle special case where 'Alias' maps to 'AccountName' |
| |
52 |
trim = False |
| |
53 |
if key == "Alias": |
| |
54 |
key = "AccountName" |
| |
55 |
trim = True |
| |
56 |
|
|
9609002e
»
|
glenc |
2008-05-17 |
Started script for setting ... |
57 |
val = profile[key].Value |
| |
58 |
|
|
f09035b3
»
|
glenc |
2008-05-17 |
Finished script to set prof... |
59 |
if trim == True: |
| |
60 |
val = val.split("\\")[1] |
| |
61 |
|
| |
62 |
value = value.replace(match.group(0), val) |
| |
63 |
|
| |
64 |
# how apply updated value to the profile property |
| |
65 |
profile[prop].Value = value |
| |
66 |
profile.Commit() |
|
9609002e
»
|
glenc |
2008-05-17 |
Started script for setting ... |
67 |
|
| |
68 |
|
| |
69 |
|
| |
70 |
if __name__ == '__main__': |
|
81bf4b5d
»
|
glenc |
2008-05-18 |
Updated script to use named... |
71 |
main(sys.argv[1:]) |