-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportingFunctions.ps1
102 lines (96 loc) · 3.64 KB
/
ReportingFunctions.ps1
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Function RunReports {
If ($ReportOnly){
speak "Running reports then quitting..."
speak ""
}
If (!($NoReport)) {
#USER REPORTS
If ($StaffUsers) {
#STAFF USER REPORTS
RunSIMSReport $SIMSStaffUsersReport $SIMSStaffList
RunLDAPUserReport $LDAPStaffUsersOU $LDAPStaffList $false $TRUE
RunLDAPUserReport $LDAPStaffUsersITSOU $LDAPStaffList
RunLDAPUserReport $LDAPStaffUsersITTOU $LDAPStaffList
}
If ($StudentUsers){
#STUDENT USER REPORTS
RunSIMSReport $SIMSStudentUsersReport $SIMSStudentList
RunLDAPUserReport $LDAPStudentUsersOU $LDAPStudentList $TRUE $TRUE
}
#GROUP REPORTS
If ($StaffGroups) {
#STAFF GROUPS REPORT
RunSIMSReport $SIMSAssociateStaffReport $SIMSAssociateStaffList
RunSIMSReport $SIMSTeachingStaffReport $SIMSTeachingStaffList
RunLDAPGroupMemberReport $LDAPAssociateStaffGroup $LDAPAssociateStaffList
RunLDAPGroupMemberReport $LDAPTeachingStaffGroup $LDAPTeachingStaffList
}
#STUDENT GROUP REPORTS
If ($RegistrationGroups) {
#REGISTRATION GROUPS REPORT
RunSIMSReport $SIMSRegGroupReport $SIMSRegGroupList
RunSIMSReport $SIMSStudentRegGroupReport $SIMSStudentRegList
}
If ($SubjectGroups -or $TeachingGroups) {
#SUBJECT GROUPS REPORT
RunSIMSReport $SIMSSubjectGroupReport $SIMSTeachingSubList
}
If ($TeachingGroups) {
#TEACHING GROUPS REPORT
RunSIMSReport $SIMSTeachingGroupReport $SIMSStudentTeachList
}
} else {
speak "Reports are not being run by user request."
}
If ($ReportOnly) {bork}
}
Function RunSIMSReport($ReportName, $OutputFile) {
If (Test-Path -Path ${OutputFile}){
Remove-Item -Path ${OutputFile} -Force -ErrorAction SilentlyContinue
}
speak "Running SIMS report ${Reportname}..." -Time
& $CommandReporter /TRUSTED /SERVERNAME:"$DBServer" /DATABASENAME:"$DBName" /REPORT:"$ReportName" /OUTPUT:"$OutputFile"
if ($? -and (Test-Path -Path ${OutputFile})) {
speak "${OutputFile} created successfully." -Time
speak ""
} else {
speak "Report failed" -Time
speak ""
}
}
Function RunLDAPUserReport($ReportOU, $OutputFile, $Recursive = $false, $FirstReport = $false) {
If ($LDAPReport) {
If (($FirstReport -eq $TRUE) -and (Test-Path -Path ${OutputFile})){
Remove-Item -Path ${OutputFile} -Force -ErrorAction SilentlyContinue
}
speak "Running LDAP report on ${ReportOU}..." -Time
If ($Recursive) {
Get-ADUser -searchbase "${ReportOU}" -filter * -Properties ${LDAPUserPropertiesArray} | Where-Object {($_.DistinguishedName -notlike '*OU=External*') -or ($_.DistinguishedName -notlike '*OU=Guests*')} |Select ${LDAPUserPropertiesArray} | Export-csv $OutputFile -Append
} else {
Get-ADUser -searchbase "${ReportOU}" -filter * -Properties ${LDAPUserPropertiesArray} -SearchScope OneLevel | select ${LDAPUserPropertiesArray} | Export-csv $OutputFile -Append
}
if ($? -and (Test-Path -Path ${OutputFile})) {
speak "${OutputFile} created successfully." -Time
speak ""
} else {
speak "Report failed" -Time
speak ""
}
}
}
Function RunLDAPGroupMemberReport($ReportGroup, $OutputFile, $OverrideNoReport = $false) {
If ($NoLDAPReport -eq $true -and $OverrideNoReport -eq $false) {
If (Test-Path -Path ${OutputFile}) {
Remove-Item -Path ${OutputFile} -Force -ErrorAction SilentlyContinue
}
speak "Running LDAP report on ${ReportGroup}..." -Time
Get-ADGroupMember -Identity ${ReportGroup} | select distinguishedname, samaccountname | Export-Csv $OutputFile
if ($? -and (Test-Path -Path ${OutputFile})) {
speak "${OutputFile} created successfully." -Time
speak ""
} else {
speak "Report failed" -Time
speak ""
}
}
}