-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeleteUsersFromCsvFile.py
More file actions
36 lines (26 loc) · 1008 Bytes
/
deleteUsersFromCsvFile.py
File metadata and controls
36 lines (26 loc) · 1008 Bytes
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
import os
import time
from ldap3.core.exceptions import LDAPException
import csvFileManagement
import logsManagement
def upload_action(connection):
# determine a good time based complement for the log filename
initial_time = time.strftime("%Y%m%d-%H%M%S")
# define the first line of the log file
initial_log = "Logs: Delete Users form CSV" + initial_time
logs = initial_log
# open csv file
data_lines = csvFileManagement.open_csv_file()
# for each line, retrieve necessary elements
for line in data_lines[1:]:
sam_account_name = line[0]
ou = line[1]
user_dn = 'cn=' + sam_account_name + ',ou=' + ou + os.environ.get("SEARCHDC")
# Delete users
try:
connection.delete(user_dn)
logs += "\n User deleted : " + user_dn
except LDAPException as e:
logs += "\n Error : " + str(e)
# print and write logs
logsManagement.write_logs(logs, initial_log, initial_time, "delete_users")