ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/MW/Training_la.py
Revision: 8
Committed: Sat May 5 04:21:19 2012 UTC (13 years, 10 months ago) by ninoborges
Content type: text/x-python
File size: 3682 byte(s)
Log Message:
Initial Import

File Contents

# Content
1 ## This program will take a list of training user accounts and, using cusrmgr.exe,
2 ## add them as local admins to every training machine in their respective offices.
3 #EBORGES
4 #05.29.02
5
6 import string, os
7
8 ## This function takes a dictionary with Username keys and multiple machine names values as an
9 ## argument and runs Cusrmgr on them, to add the Username to the machine's local admin group.
10 def AddLocalAdmin(dict):
11 errorlist = []
12 nochangelist = []
13
14 ## These 2 or loops unpack the dictionary, strip off the carrige returns and run Cusrmgr on them.
15 ## They also add the machine and username to a list in case Cusrmgr either fails or sees that this
16 ## user account is already a local admin.
17 for k in dict.keys():
18 user = string.split(k,'\n')
19 user = user[0]
20 for y in dict[k]:
21 machine = string.split(y,'\n')
22 machine = machine[0]
23 print "Adding %s as a local administrator of machine %s..."%(user,machine)
24 status = os.system('cusrmgr.exe -u %s -m \\\%s -alg Administrators'%(user,machine))
25 #print 'cusrmgr.exe -u %s -m \\\%s -alg Administrators'%(user,machine)
26
27 ## If its sucessful
28 if status == 0:
29 print "%s has been added to %s sucessfully!"%(user,machine)
30
31 ## If it sees that the user account is already a local admin.
32 elif status == 1378:
33 print "%s is already a member of the administrators group on %s!"%(user,machine)
34 ## Append the username and machine name to the list for reporting later
35 nochangelist.append([user,machine])
36
37 ## If it fails
38 else:
39 print "Adding %s as a local administrator of machine %s failed!"%(user,machine)
40 ## Append the username and machine name to the list of reporting later.
41 errorlist.append(user,machine)
42
43 ## Print out the Final report to stdout
44 print ""
45 print "Final report."
46 print "----------------------------------"
47 print "%i machines left unchanged because they already had the account"% len(nochangelist)
48 print "List of machines left unchanged:",nochangelist
49 print "%i machines that failed!"% len(errorlist)
50 print "List of machines that failed:",errorlist
51 print "END"
52
53 if __name__=='__main__':
54 ##Creating an empty dictionary
55 dict={}
56
57 ##Getting the list of names from a file
58 n=open('C:\\Training_proj\\user_names.txt','r')
59 names = n.readlines()
60 n.close()
61
62 ## This for loop removes the "mwbb\\" from the user name, gets the list of machines from a file
63 ## and adds the the username and machines to the dictionary.
64 ## 06.19.02 CHANGE: The user name is now MWBB.DOM/username instead of just username. This is because
65 ## Cusrmgr will not allow usernames to be the same as the computername unless its
66 ## absolute. Ie. it will allow pittrain1 to be added to PITTRAIN2 but not pitrain1 to
67 ## be added to PITTRAIN1.
68 for name in names:
69 full_name = name
70 name = string.split(name,"\\")
71 name = name[1]
72 office = name[:3]
73 string.lower(office)
74 machine_file = 'c:\\Training_proj\\%s_machine_name.txt' % office
75 m=open(machine_file,'r')
76 machines = m.readlines()
77 m.close()
78 dict[full_name]=machines
79 ## Calls the AddLocalAdmin function to unpack the dictionary and process each entry.
80 AddLocalAdmin(dict)