-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-assetpanda-employees.py
64 lines (38 loc) · 1.41 KB
/
get-assetpanda-employees.py
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
52
53
54
55
56
57
58
59
60
61
62
63
from mit_moira import Moira
import csv
# Initialize Moira client with X.509 certificate and private key file
moira = Moira("OUTFILE.cert", "OUTFILE.pem")
def getlist (listname):
print(Moira.list_exists(moira, listname))
def getlistmembers (listname):
return Moira.list_members(moira,listname, type='USER', recurse=True, max_results=1000)
def getlistmemberinfo (username):
#populate user fields
members = Moira.list_user_info(moira,username)
return [members["first"] + " " + members["last"], members["mitid"],"",members["userName"]+'@mit.edu',"","","","","","","",""]
def getbulklistmemmberinfo(users):
arr = []
for user in users:
arr.append(getlistmemberinfo(user))
return arr
def getlistattributes (listname):
print(Moira.list_attributes(moira, listname))
"""
Output CSV
"""
# field names
fields = ['Name', 'Employee ID', 'Job Title', 'Email', 'Phone', 'Status', 'Jamf Pro ID', 'SCCM ID', 'Images', 'Documents']
# data rows of csv file
userlist = getlistmembers("archall")
rows = getbulklistmemmberinfo(userlist)
print(rows)
# name of csv file
filename = "assetpanda-employees.csv"
# writing to csv file
with open(filename, 'w') as csvfile:
# creating a csv writer object
csvwriter = csv.writer(csvfile)
# writing the fields
csvwriter.writerow(fields)
# writing the data rows
csvwriter.writerows(rows)