-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWork.psm1
233 lines (215 loc) · 6.02 KB
/
Work.psm1
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#Author: Jorge Cisneros
#
# Purpose: Functions to use at work
Function time {
clear
[System.Console]::CursorVisible = $false
$weather = weather -n
$hour = (Get-Date).Hour
while($true) {
$now = (Get-Date).Hour
if ($now -gt $hour) {
$weather = weather -n
$hour = (Get-Date).Hour
clear
}
[System.Console]::SetCursorPosition(0, 0)
Write-Host "$(date) $weather" -NoNewLine
sleep 1
}
}
Function aklogin {
param(
[switch]$u,
[switch]$t,
[string]$user
)
switch ($true) {
$u {
$a = Get-Content "\\KCL-WEB01\c$\Public\Login.txt"
foreach ($b in $a) {
if ($b.Contains($user)) {
Write-Host $b
}
}
}
$t {
Get-Content "\\KCL-WEB01\c$\Public\Login.txt" -Tail 50
}
Default {
Get-Content "\\KCL-WEB01\c$\Public\Login.txt"
}
}
}
Function akgeneral {
param(
[switch]$t
)
switch ($true) {
$t {
Get-Content "\\KCL-WEB01\c$\Public\General.txt" -Tail 50
}
Default {
Get-Content "\\KCL-WEB01\c$\Public\General.txt"
}
}
}
Function aklogs {
$t = 60*15
while ($true) {
aklogin -t
sleep $t
akgeneral
sleep $t
}
}
Function stu {
param(
[int]$ID
)
if (Get-Module -ListAvailable SqlServer) {
Import-Module -Name SqlServer
} else {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet -Force
Install-Module -Name SqlServer -Scope CurrentUser -Force
Import-Module -Name SqlServer
}
$SqlServer = "KCL-SQL01"
$SqlDBName = "TmsEPrd"
$SchemaName = "dbo"
function Student-Master {
param(
[int]$ID
)
Invoke-Sqlcmd -ServerInstance $SqlServer -Encrypt Optional -Query "
SELECT
'ID' = SM.ID_NUM,
'Last' = NM.LAST_NAME,
'First' = NM.FIRST_NAME,
'Middle' = NM.MIDDLE_NAME,
'Active' = IS_STUDENT_ACTIVE,
'Start Year' = SM.ENTRANCE_YR,
'Start Term' = SM.ENTRANCE_TRM
FROM $SqlDBName.$SchemaName.STUDENT_MASTER SM
JOIN $SqlDBName.$SchemaName.NameMaster NM ON SM.ID_NUM = NM.ID_NUM
WHERE SM.ID_NUM = $ID"
}
function Student-Courses {
param(
[int]$ID
)
Invoke-Sqlcmd -ServerInstance $SqlServer -Encrypt Optional -Query "
SELECT
Top 4
'ID' = ID_NUM,
'Year' = YR_CDE,
'Term' = TRM_CDE,
'Course' = CRS_TITLE,
'Add' = ADD_DTE,
'Start' = BEGIN_DTE,
'End' = END_DTE
FROM $SqlDBName.$SchemaName.STUDENT_CRS_HIST
WHERE ID_NUM = $ID
ORDER BY YR_CDE DESC"
}
function Lookup {
param(
[int]$ID
)
Write-Host "AD Info"
Get-ADUser $ID
Write-Host "Master Info"
Student-Master -ID $ID
Write-Host "Courses"
Student-Courses -ID $ID
}
try {
Lookup -ID $ID
}
catch {
$errorMessage = "Error occurred: $_"
Write-Host $errorMessage
}
}
Function emp {
param(
[string]$first,
[string]$last
)
if (Get-Module -ListAvailable SqlServer) {
Import-Module -Name SqlServer
} else {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet -Force
Install-Module -Name SqlServer -Scope CurrentUser -Force
Import-Module -Name SqlServer
}
$SqlServer = "KCL-SQL01"
$SqlDBName = "TmsEPrd"
$SchemaName = "dbo"
function Name-Master {
param(
[string]$first,
[string]$last
)
Invoke-Sqlcmd -ServerInstance $SqlServer -Encrypt Optional -Query "
SELECT
'ID' = NM.ID_NUM,
'Last' = LAST_NAME,
'First' = FIRST_NAME,
'Middle' = MIDDLE_NAME,
'Active' = ACT_INACT_STS,
'Confirmed' = DTE_CONFIRMED,
'Hired' = ORIG_HIRE_DTE,
'Start' = FULLTIME_START_DTE,
'Group' = GRP_CDE,
'Phone' = EWL.PHONE_NUMBER,
'Termed' = TERMINATION_DTE
FROM $SqlDBName.$SchemaName.NameMaster NM
JOIN $SqlDBName.$SchemaName.EMPL_MAST EM ON EM.ID_NUM = NM.ID_NUM
JOIN $SqlDBName.$SchemaName.EMPL_WRK_LOC EWL ON EWL.ID_NUM = NM.ID_NUM
WHERE NM.FIRST_NAME = '$first' AND NM.LAST_NAME = '$last'"
}
function OnGoing-Load {
param(
[string]$first,
[string]$last
)
Invoke-Sqlcmd -ServerInstance $SqlServer -Encrypt Optional -Query "
SELECT
'Operation' = OperationDate,
'Type' = OperationType,
'Last' = LastName,
'First' = FirstName,
'Middle' = MiddleName,
'Email' = WorkEmailID,
'Phone' = WorkPhone,
'Code' = AgencyCode,
'User' = AgencyUserID,
'Add' = AddApplicationAccess,
'Remove' = RemoveApplicationAccess
FROM $SqlDBName.$SchemaName.KCT_003580_ONGOING_LOAD
WHERE FirstName = '$first' AND LastName = '$last'"
}
function Lookup {
param(
[string]$first,
[string]$last
)
$initial = $first[0]
Write-Host "AD Info"
Get-ADUser $initial$last
Write-Host "Master Info"
Name-Master -first $first -last $last
Write-Host "Load Info"
OnGoing-Load -first $first -last $last
}
try {
Lookup -first $first -last $last
}
catch {
$errorMessage = "Error occurred: $_"
Write-Host $errorMessage
}
}