-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCGUI_Normal.ps1
More file actions
2061 lines (1784 loc) · 72.2 KB
/
Copy pathSCGUI_Normal.ps1
File metadata and controls
2061 lines (1784 loc) · 72.2 KB
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
####---------------------------------------------------------------------------------------------####
# Service Center Exchange GUI #
# Written by: Austin Heyne #
# #
# --Information-- #
# Program provides an interface to manage day to day operations in Exchange 2010. This is the #
# non-administrative version, it has substantailly more error handling than the Admin version but #
# also takes longer to open due to creating all the custom error records. It also has sligtly less #
# functionality as restricted functions have been removed. #
####---------------------------------------------------------------------------------------------####
#Generated Form Function
function GenerateForm {
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Form Objects
$SCEGUI = New-Object System.Windows.Forms.Form
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$tabControl1 = New-Object System.Windows.Forms.TabControl
#DL Tab
$tabPageDL = New-Object System.Windows.Forms.TabPage
$groupBox2 = New-Object System.Windows.Forms.GroupBox
$CB_Sponsors = New-Object System.Windows.Forms.CheckBox
$RTB_Members = New-Object System.Windows.Forms.RichTextBox
$label4 = New-Object System.Windows.Forms.Label
$RTB_DLOutput = New-Object System.Windows.Forms.RichTextBox
$Create = New-Object System.Windows.Forms.Button
$ListInGAL = New-Object System.Windows.Forms.CheckBox
$groupBox1 = New-Object System.Windows.Forms.GroupBox
$RB_IO = New-Object System.Windows.Forms.RadioButton
$RB_OO = New-Object System.Windows.Forms.RadioButton
$RB_MO = New-Object System.Windows.Forms.RadioButton
$RB_A = New-Object System.Windows.Forms.RadioButton
$TB_EmailAddress = New-Object System.Windows.Forms.TextBox
$label3 = New-Object System.Windows.Forms.Label
$TB_Sponsors = New-Object System.Windows.Forms.TextBox
$label2 = New-Object System.Windows.Forms.Label
$TB_Alias = New-Object System.Windows.Forms.TextBox
$UseCustomAlias = New-Object System.Windows.Forms.CheckBox
$TB_DGN = New-Object System.Windows.Forms.TextBox
$label1 = New-Object System.Windows.Forms.Label
#Quota Tab
$tabPageIQ = New-Object System.Windows.Forms.TabPage
$B_IQ_SetMax = New-Object System.Windows.Forms.Button
$B_IQ_SetDefault = New-Object System.Windows.Forms.Button
$label_IQ_Out = New-Object System.Windows.Forms.Label
$B_IQ_Check = New-Object System.Windows.Forms.Button
$TB_IQName = New-Object System.Windows.Forms.TextBox
$label_IQ_7 = New-Object System.Windows.Forms.Label
#CMSTab
$CMS_Tab = New-Object System.Windows.Forms.TabPage
$CMS_Progress = New-Object System.Windows.Forms.ProgressBar
$CMS_Status = New-Object System.Windows.Forms.Label
$CMS_Members = New-Object System.Windows.Forms.RichTextBox
$CMS_label3 = New-Object System.Windows.Forms.Label
$CMS_Create = New-Object System.Windows.Forms.Button
$CMS_Owners = New-Object System.Windows.Forms.TextBox
$CMS_label2 = New-Object System.Windows.Forms.Label
$CMS_label1 = New-Object System.Windows.Forms.Label
$CMS_Group = New-Object System.Windows.Forms.TextBox
#roomview
$RV_Tab = New-Object System.Windows.Forms.TabPage
$RV_Status = New-Object System.Windows.Forms.Label
$RV_button1 = New-Object System.Windows.Forms.Button
$RV_textBox2 = New-Object System.Windows.Forms.TextBox
$RV_label2 = New-Object System.Windows.Forms.Label
$RV_label1 = New-Object System.Windows.Forms.Label
$RV_textBox1 = New-Object System.Windows.Forms.TextBox
#Console
$tabPageConsole = New-Object System.Windows.Forms.TabPage
$RTB_Console = New-Object System.Windows.Forms.RichTextBox
#endregion Form Objects
#region Create DL
$Create_OnClick=
{
#Clear any text from DLOutput
. updateDLOutput ""
. updateDLOutput "Creating DL..."
try{
#-------Import and Sanatize Data-------#
Write-debug "1"
if(-not $TB_DGN.Text -match $global:regex_DGN){
Write-Debug $TB_DGN.Text
throw $Global:Error_InvalidDGN
}
if($UseCustomAlias.Checked -is $true){
if(-not $TB_Alias.Text -match $global:regex_Alias){
throw $Global:Error_InvalidAlias
}
}
if(-not $TB_EmailAddress.Text -match $global:regex_Email){
throw $Global:Error_InvalidEmailAddress
}
if(-not $TB_Sponsors.Text -match $global:regex_SponsorList){
$msg = "There is an invalid charater in the Sponsors list, please correct."
popupError($msg,0,"Invalid Imput",0x0)
throw $Global:Error_BadSponsor
}
if(-not $RTB_Members.Text -match $global:regex_MemberList){
$msg = "There is an invalid character in the Members list, please correct."
popupError($msg,0,"Invalid Imput",0x0)
throw $Global:Error_BadMember
}
#-------Alias - Handle Generated Alias or Custom Alias-------#
if($UseCustomAlias.Checked){
$DL_Alias = $TB_Alias.Text
} else {
$DL_Alias = $TB_DGN.Replace(" ","").Replace("(","").Replace(")","").Replace(",","").Replace("-","")
}
#Make sure the group doens't exist already, this happens more than you would think.
Get-ADGroup $DL_Alias
if($?){
throw $Global:Error_AlreadyExists
}
. updateDLOutput ("DGN: " + $TB_DGN)
. updateDLOutput ("Alias: " + $DL_Alias)
#-------Sponsors - Handle Sponsor Check-------#
if($TB_Sponsors.Text.Replace(" ","") -match $global:regex_SponsorList){
$sponsorList = $S_Sponsors.Text.Replace(" ","").Split(",")
$sponsorList = $sponsorList | Select-Object -Unique
if($sponsorList.Length -lt 2){
. updateDLOutput "Not enough sponsors provided."
throw $Global:Error_InsufficientSponsors
} else {
foreach($_ in $sponsorList){
#Sanitize each sponsor
if(-not $_ -match $global:regex_4x4){
popupError(($_ + " is not a valid 4x4."),0,"Invalid Imput",0x0)
throw $Global:Error_BadSponsor
}
#check existance
Get-ADUser $_
if(!$?){
popupError(($_ + " is not a valid 4x4"),0,"Invalid 4x4",0x0)
throw $Global:Error_BadSponsor
}
}
. updateDLOutput "Sponsors Approved"
}
} else {
throw $Global:Error_InvalidSponsorList
}
#-------Members - Handle Member Check-------#
if($RTB_Members.Text.Replace(" ","") -match $global:regex_MemberList){
$memberList = $RTB_Members.Text.Replace(" ","").Split("`n")
$memberList = $memberList | Select-Object -Unique
if($memberList.Length -gt 0){
foreach($_ in $memberList){
#Sanitize each member
if(-not $_ -match $global:regex_4x4){
popupError(($_ + " is not a valid 4x4."),0,"Invalid Imput",0x0)
throw $Global:Error_BadMember
}
#check existance
Get-ADUser $_
if(!$?){
popupError(($_ + " is not a valid 4x4"),0,"Invalid 4x4",0x0)
throw $Global:Error_BadMember
}
}
. updateDLOutput "Members Approved"
}
} else {
throw $Global:Error_InvalidMemberList
}
#-------Create DL-------#
New-DistributionGroup -Alias $DL_Alias -Name $TB_DGN.text -Type Distribution -OrganizationalUnit OU="DLs,OU=Exchange,dc=sooner,dc=net,dc=ou,dc=edu" -SamAccountName $DL_Alias -ManagedBy $sponsorList | Out-String -Stream | ForEach-Object {
. updateConsole $_
}
if(!$?){
. updateDLOutput "Error Creating DL, See Console"
throw $Global:Error_Unknown
} else {
. updateDLOutput "DL Created."
}
#-------Modify Email Address Policy-------#
Set-DistributionGroup $TB_DGN -EmailAddressPolicyEnabled $false | Out-String | ForEach-Object {
. updateConsole $_
}
#-------Add Default Email Address-------#
$emailAddresses = $(Get-DistributionGroup $TB_DGN).EmailAddresses
$newAddress = "SMTP:" + $DL_Alias + "@sooner.net.ou.edu"
$emailAddresses += $newAddress
Set-DistributionGroup $TB_DGN -EmailAddresses $emailAddresses | Out-String | ForEach-Object {
. updateConsole $_
}
. updateDLOutput "Email Addresses:"
foreach($_ in $emailAddresses){
. updateDLOutput $_
}
#-------Add @ou.edu Email Address-------#
if($TB_EmailAddress.Replace(" ","") -match $global:regex_Email){
#Check the Email address is not in use by DLs or Mailboxes
Get-DistributionGroup ($TB_EmailAddress.Text.Replace(" ","") + "@ou.edu")
if($?){
throw $Global:Error_EmailAddressInUse
}
Get-Mailbox ($TB_EmailAddress.Text.Replace(" ","") + "@ou.edu")
if($?){
throw $Global:Error_EmailAddressInUse
}
#Add email address
$newAddress = "SMTP:" + $TB_EmailAddress.Text.Replace(" ","") + "@ou.edu"
$emailAddresses += $newAddress
Set-DistributionGroup $TB_DGN.Text -EmailAddresses $emailAddresses | Out-String | ForEach-Object {
. updateConsole $_
}
if(!$?){
. updateDLOutput "Error adding @ou.edu address, See Console"
} else {
. updateDLOutput "Added " + $newAddress
}
} else {
#this is handled in initial sanitization, should never reach here.
throw $Global:Error_Unknown
}
#-------List in GAL?-------#
if($ListInGAL.Checked){
Set-DistributionGroup $TB_DGN -HiddenFromAddressListsEnabled $false
} else {
Set-DistributionGroup $TB_DGN -HiddenFromAddressListsEnabled $true
}
#-------Handle who can send to list-------#
if($RB_A.Checked){
#Anyone
Set-DistributionGroup $TB_DGN -RequireSenderAuthenticationEnabled $false
}
elseif($RB_MO.Checked){
#Members Only
Set-DistributionGroup $TB_DGN -AcceptMessagesOnlyFromDLMembers $TB_DGN
}
elseif($RB_OO.Checked){
#Owners Only
#This creates another DL called $DL_Alias + "-group" that is used as the group that can send to DL
New-DistributionGroup -Alias ($DL_Alias + "-group") -Name ($DL_Alias + "-group") -Type Security -OrganizationalUnit OU="DLs,OU=Exchange,dc=sooner,dc=net,dc=ou,dc=edu" -SamAccountName ($DL_Alias + "-group")
#Make universal group
Set-ADGroup -Identity ($DL_Alias + "-group") -GroupScope Universal
#Mail Enable group (May error out and silently continue from already being set)
Enable-DistributionGroup ($DL_Alias + "-group") 2> $null
#Wait for new DL to replicate
. updateDLOutput "Please wait 60 seconds for Owners Group to replicate"
. progressBar 60 "Waiting for replication..." "Please wait 60 seconds for Owners Group to replicate"
Set-DistributionGroup ($DL_Alias + "-group") -HiddenFromAddressListsEnabled $true
Set-DistributionGroup ($DL_Alias + "-group") -AcceptMessagesOnlyFromDLMembers ($DL_Alias + "-group")
$sponsorList | foreach {
Add-DistributionGroupMember -Identity ($DL_Alias + "-group") -Member $_
}
Set-DistributionGroup $TB_DGN -AcceptMessagesOnlyFromDLMembers ($DL_Alias + "-group")
}
elseif($RB_IO.Checked){
#Internal Only
Set-DistributionGroup $TB_DGN -RequireSenderAuthenticationEnabled $true
}
else{
#How'd you get here?
throw $Global:Error_Unknown
}
#-------Handle list membership-------#
if($CB_Sponsors.Checked){
$memberList = $memberList + $sponsorList | Select-Object -Unique
$memberList | foreach {
Add-DistributionGroupMember -Identity $TB_DGN -Member $_
}
. updateDLOutput "Sponsors and Members added as members to DL"
}
elseif($memberList.Length -gt 0){
$memberList | foreach {
Add-DistributionGroupMember -Identity $TB_DGN -Member $_
}
. updateDLOutput "Members added to DL"
}
else {
. updateDLOutput "No Members added to DL"
}
. updateDLOutput "DL created without errors."
#Clear Form
$TB_Alias.Text = ""
$TB_DGN.Text = ""
$TB_EmailAddress.Text = ""
$TB_Sponsors.Text = ""
$UseCustomAlias.Checked = $false
$RB_A.Checked = $true
$RTB_Members.Text = ""
} catch {
#-------Input errors-------#
#Catch invalid dgn
if($error[0].FullyQualifiedErrorId -match "InvalidDGN"){
$msg = "No distribution group name or an invalid distribution group name was provided."
popupError $msg 0 "Invalid Input" 0x0
}
if($error[0].FullyQualifiedErrorId -match "InvalidAlias"){
$msg = "No Alias was provided when 'Use Custom Alias' was checked or a bad Alias was provided."
popupError $msg 0 "Invalid Input" 0x0
}
#Catch invalid email address
if($error[0].FullyQualifiedErrorId -match "InvalidEmailAddress"){
$msg = "No email address or an invalid email address was provided."
popupError $msg 0 "Invalid Input" 0x0
}
#Catch input sanitization errors.
if($error[0].FullyQualifiedErrorId -match "InputSanitizationError"){
$msg = "Error in sanitizing input. Please validate data fields and try agian. If this error continues please ensure compliance with documented guidelines or contact the Exchange Team."
popupError $msg 0 "Invalid Input" 0x0
}
#Catch invalid sponsor list input
if($error[0].FullyQualifiedErrorId -match "NoSponsorList"){
$msg = "No sponsor list was provided. Every DL requires a minimum of 2 sponsors. If for some reason only one is available please create a case and assign it to the Exchange Team. Do NOT use yours or another 4x4 to comply."
popupError($msg,0,"Invalid Imput",0x0)
}
#Catch invalid data in sponsor list
if($error[0].FullyQualifiedErrorId -match "InvalidSponsorList"){
$msg = "There is an invalid character in the sponsor list."
popupError($msg,0,"Invalid Imput",0x0)
}
#Catch invalid data in member list
if($error[0].FullyQualifiedErrorId -match "InvalidMemberList"){
$msg = "There is an invalid character in the member list."
popupError($msg,0,"Invalid Imput",0x0)
}
#Catch insufficient number of sponsors
if($error[0].FullyQualifiedErrorId -match "InsufficientSponsors"){
$msg = "Not enough sponsors were provided. Every DL requires a minimum of 2 sponsors. If for some reason only one is available please create a case and assign it to the Exchange Team. Do NOT use yours or another 4x4 to comply."
popupError($msg,0,"Invalid Imput",0x0)
}
#Catch bad sponsor 4x4
if($error[0].FullyQualifiedErrorId -match "BadSponsor"){
#error handling before throw so we can include offending 4x4
}
#Catch bad member 4x4
if($error[0].FullyQualifiedErrorId -match "BadMember"){
#error handling before throw so we can include offending 4x4
}
#Catch object already exists
if($error[0].FullyQualifiedErrorId -match "AlreadyExists"){
$msg = "The object you are trying to create already exists."
popupError($msg,0,"Object already exists",0x0)
}
if($error[0].FullyQualifiedErrorId -match "EmailAddressInUse"){
$msg = "The Email Address provided is already in use."
popupError($msg,0,"Address in use",0x0)
}
#-------Script errors-------#
#Catch internal coding errors with the sanitiazation function.
if($error[0].FullyQualifiedErrorId -match "MalformedSanitizationRequest"){
$msg = "An internal error has occured attempting to sanitize user input. Please contact the Exchange Team with error code: DLSE1"
popupError($msg, 0, "Invalid Sanitization Request", 0x0)
}
#Something bad happened and I don't know what
if($error[0].FullyQualifiedErrorId -match "UnknownScriptError"){
$msg = "Something bad happened and I don't know what. Check console for errors. DL may have been created, verify existance before trying agian. If you cannot resolve any issues experienced or created contact Exchange Team."
popupError($msg,0,"Object already exists",0x0)
}
}
}
#endregion Create DL
#region Increase Quota
$B_IQ_Check_OnClick=
{
Write-Debug "IQ Check OnClick"
Write-Debug $TB_IQName.Text
if(-not $TB_IQName.Text.Replace(" ","") -match $global:regex_4x4){
Write-Debug "Bad Input"
$label_IQ_Out.Text = "Please input valid 4x4."
$SCEGUI.Update()
} else {
try{
$IQ_MB_REF = $TB_IQName.Text.Replace(" ","")
$IQ_MB_OBJ = get-mailbox $IQ_MB_REF
if(!$?){
throw $Global:Error_InvalidRef
}
$IQ_MB_USED = Get-MailboxStatistics $IQ_MB_REF
$label_IQ_Out.Text = $IQ_MB_OBJ.SamAccountName + "'s current quota is " + $IQ_MB_OBJ.ProhibitSendQuota.Value.ToGB() + "GB, Used: " + $IQ_MB_USED.TotalItemSize.Value.ToGB() + " GB."
}catch{
#Catch invalid 4x4
if($error[0].FullyQualifiedErrorId -match "InvalidRef"){
$msg = "The 4x4 or Email provided is not valid for this request."
popupError $msg 0 "Invalid Input" 0x0
}
}
}
}
$B_IQ_SetDefault_OnClick=
{
if(-not $TB_IQName.Text.Replace(" ","") -match $global:regex_4x4){
Write-Debug "Bad Input"
$label_IQ_Out.Text = "Please input valid 4x4."
$SCEGUI.Update()
}else{
try{
$IQ_MB_REF = $TB_IQName.Text.Replace(" ","")
$IQ_MB_OBJ = get-mailbox $IQ_MB_REF
if(!$?){
throw $Global:Error_InvalidRef
}
Set-Mailbox -IssueWarningQuota '5.841 GB (6,271,533,056 bytes)' -ProhibitSendQuota '6 GB (6,442,450,944 bytes)' -Identity $IQ_MB_REF
#This is safe todo because the Regex check ensures that the input is not a wildcard
$IQ_MB_OBJ = Get-Mailbox $IQ_MB_REF
$label_IQ_Out.Text = $IQ_MB_OBJ.SamAccountName + "'s current quota is " + $IQ_MB_OBJ.ProhibitSendQuota
}catch{
#Catch invalid 4x4
if($error[0].FullyQualifiedErrorId -match "InvalidRef"){
$msg = "The 4x4 or Email provided is not valid for this request."
popupError $msg 0 "Invalid Input" 0x0
}
}
}
#clear form
$TB_IQName.Text = ""
}
$B_IQ_SetMax_OnClick=
{
if(-not $TB_IQName.Text.Replace(" ","") -match $global:regex_4x4){
$label_IQ_Out.Text = "Please input valid 4x4."
$SCEGUI.Update()
}else{
try{
$IQ_MB_REF = $TB_IQName.Text.Replace(" ","")
$IQ_MB_OBJ = get-mailbox $IQ_MB_REF
if(!$?){
throw $Global:Error_InvalidRef
}
Set-Mailbox -IssueWarningQuota 11GB -ProhibitSendQuota 12GB -Identity $IQ_MB_REF
#This is safe todo because the Regex check ensures that the input is not a wildcard
$IQ_MB_OBJ = Get-Mailbox $IQ_MB_REF
$label_IQ_Out.Text = $IQ_MB_OBJ.SamAccountName + "'s current quota is " + $IQ_MB_OBJ.ProhibitSendQuota
}
catch{
#Catch invalid 4x4
if($error[0].FullyQualifiedErrorId -match "InvalidRef"){
$msg = "The 4x4 or Email provided is not valid for this request."
popupError $msg 0 "Invalid Input" 0x0
}
}
}
#clear form
$TB_IQName.Text = ""
}
#endregion Increase Quota
#region CMS Group
$handler_CMS_Create_Click=
{
#CMS groups are basically DLs but in a different OU with a little less config.
#clear form
$CMS_Status.text = ""
#setup progress bar
$CMS_Progress.Value = 0
$CMS_Progress.Step = 100/12
try{
. cmsUpdateProgress "Validating Input Data"
#pull and sanitize data from form
if($CMS_Group.Text.Replace(" ","") -match $global:regex_Alias){
$alias = $CMS_Group.Text.Replace(" ","")
} else {
throw $Global:Error_InvalidDGN
}
#Sponsors - Handle Sponsor Check
if($CMS_Owners.Text.Replace(" ","") -match $global:regex_SponsorList){
$ownerList = $CMS_Owners.Text.Replace(" ","").TrimEnd(",").Split(",")
$ownerList = $ownerList | Select-Object -Unique
if($ownerList.Length -lt 1){
throw $Global:Error_InsufficientOwner
} else {
foreach($_ in $ownerList){
#sanitize each owner
if(-not $_ -match $global:regex_4x4){
popupError(($_ + " is not a valid 4x4."),0,"Invalid 4x4",0x0)
throw $Global:Error_BadOwner
}
Get-ADUser $_
if(!$?){
popupError(($_ + " is not a valid 4x4."),0,"Invalid 4x4",0x0)
throw $Global:Error_BadOwner
}
}
}
} else {
$ownerList = "BadData"
popupError(("There are invalid characters in the Owners' field."),0,"Invalid Input",0x0)
throw $Global:Error_BadOwner
}
#Members - Handle Member Check
if($CMS_Members.Text.Replace(" ","") -match $global:regex_MemberList){
$memberList = $CMS_Members.Text.Replace(" "."").TrimEnd(",").Split(",")
$memberList = $memberList | Select-Object -Unique
foreach($_ in $memberList){
if(-not $_ -match $global:regex_4x4){
popupError(($_ + " is not a valid 4x4"),0,"Invalid Imput",0x0)
throw $Global:Error_BadMember
}
Get-ADUser $_
if(!$?){
popupError(($_ + " is not a valid 4x4"),0,"Invalid Imput",0x0)
throw $Global:Error_BadMember
}
}
} else {
popupError(("There are invalid characters in the Members' field"),0,"Invalid Imput",0x0)
throw $Global:Error_BadMember
}
#start progress bar
. cmsUpdateProgress "Data Validated, Creating Group"
#create dl
new-DistributionGroup -alias $alias -name $CMS_Group.text -type security -org "OU=CMS,OU=DLs,OU=Exchange,dc=sooner,dc=net,dc=ou,dc=edu" -SamAccountName $alias
#update progress
. cmsUpdateProgress "Setting Email Policy"
#config dl
set-distributiongroup $alias -BypassSecurityGroupManagerCheck -EmailAddressPolicyEnabled $false
#update progress
. cmsUpdateProgress "Setting Owners"
#set managers
$DLMangers = (Get-DistributionGroup $alias).ManagedBy
foreach($_ in $ownerList){
$DLMangers += $_
}
Set-DistributionGroup $alias -ManagedBy $DLMangers
#wait for replication
. cmsUpdateProgress "Waiting for Replication"
$i = 0
do{
sleep 1
$i++
. cmsUpdateProgress "Waiting for Replication"
} while ($i -lt 4)
#update progress
. cmsUpdateProgress "Setting Address"
#set email address
set-distributiongroup $alias -PrimarySMTPAddress $alias@ou.edu
#add members, not required
if($memberList.Length -gt 0){
. cmsUpdateProgress "Adding Members"
foreach($_ in $memberList){
Add-DistributionGroupMember -Identity $alias -Member $_
}
$CMS_Status.text = "Members Added"
$SCEGUI.Update()
}
#update progress
. cmsUpdateProgress "Verifying Data"
#gather updated data
$dlname = (Get-DistributionGroup $alias@ou.edu).name
$dladdress = (Get-DistributionGroup $alias@ou.edu).PrimarySmtpAddress
#check values and update final status
if ($dlname -ne "" -and $dladdress -ne "") {
#everything worked
$CMS_Progress.Value = 100
$CMS_Status.text = "Done: " + $dlname + " / " + $dladdress
sleep 2
} else {
$CMS_Status.text = "Something didn't work right. See console"
}
}
catch{
if($error[0].FullyQualifiedErrorId -match "InvalidDGN"){
$msg = "The provided name does not comply with naming requirements."
popupError($msg,0,"Invalid Imput",0x0)
}
if($error[0].FullyQualifiedErrorId -match "BadOwner"){
#error handling before throw so we can include offending 4x4
}
if($error[0].FullyQualifiedErrorId -match "BadMember"){
#error handling before throw se we can include the offending 4x4
}
if($error[0].FullyQualifiedErrorId -match "InsufficientOwners"){
$msg = "Not enough owners were provided. Every CMS Group requires atleast 1 owner. If for some reason none are available please create a case and assign it to the Exchange Team. Do NOT use yours or another 4x4 to comply."
popupError($msg,0,"Invalid Imput",0x0)
}
}
#clear form
$CMS_Group.text = ""
$CMS_Owners.text = ""
$CMS_Members.text = ""
$CMS_Progress.Value = 0
}
#endregion CMS Group
#region Roomview
$RV_button1_OnClick=
{
Write-Debug "Button Press"
try{
Write-Debug "Starting"
. updateRVStatus "Starting"
#-------Variables-------#
Write-Debug "1"
$password = ConvertTo-SecureString ("sooner" + (get-date).toString("yyMMdd")) -AsPlainText -Force
$name = $RV_textBox1.text
$alias = $RV_textBox2.text
if(!($name -match $global:regex_Alias)) {throw $Global:Error_InvalidName}
if(!($alias -match $global:regex_Alias)) {throw $Global:Error_InvalidAlias}
$groupName = $alias + "-group"
. updateRVStatus "Input approved."
sleep 1
Write-Debug "Creating"
Write-Debug $name
Write-Debug $alias
Write-Debug $groupName
#-------Create and Configure-------#
. updateRVStatus "Creating mailbox"
Write-Debug "New-Mailbox"
New-Mailbox -Name $name -DisplayName $name -Alias $alias -UserPrincipalName ($alias + "@ou.edu") -Password $password
. updateRVStatus "Configuring mailbox"
Write-Debug "Set-Mailbox"
Set-Mailbox $alias -EmailAddresses @{add=($alias + "@ou.edu")}
Set-Mailbox $alias -Type Room -EmailAddressPolicyEnabled $false -PrimarySmtpAddress ($alias + "@ou.edu")
. updateRVStatus "Creating access group"
Write-Debug "New-DistributionGroup"
New-DistributionGroup -DisplayName $groupName -Name $groupName -OrganizationalUnit "ou=Groups,ou=resource mailboxes,ou=exchange,dc=sooner,dc=net,dc=ou,dc=edu"
. updateRVStatus "Waiting for replication."
sleep 30
Write-Debug "Set-Group"
Set-Group $groupName -Universal -ErrorAction SilentlyContinue
Write-Debug "Add-ADGroupMember"
. updateRVStatus "Add-AdGroupMember"
Add-DistributionGroupMember $groupName -Member "it_roomview"
Write-Debug "Add-MailboxPermissions"
sleep 10
. updateRVStatus "Add-MailboxPermissions"
Add-MailboxPermission -Identity $name -User $groupName -AccessRights FullAccess
. updateRVStatus "Moving Mailbox"
Write-Debug "Move-ADObject"
get-aduser $alias | Move-ADObject -TargetPath "ou=roomview,ou=resource mailboxes,ou=exchange,dc=sooner,dc=net,dc=ou,dc=edu"
. updateRVStatus $($name + " created and configured; validating...")
#-------Validate Results-------#
Write-Debug "Validate Results"
$mailbox = Get-Mailbox $name
$group = Get-Group $groupName
if(!$mailbox){throw $Global:Error_MailboxNotFound}
if(!($name -eq $mailbox.Name -and $name -eq $mailbox.DisplayName)){throw $Global:Error_NameValidation}
if(!($alias -eq $mailbox.Alias)){throw $Global:Error_AliasValidation}
if(!((Get-DistributionGroupMember $groupName).Name -contains 'it_roomview')){throw $Global:Error_MembershipValidation}
. updateRVStatus "Results Validated"
sleep 1
#-------Send Record to Service Now-------#
. updateRVStatus "Sending Record"
$body = $global:CurrentUser + " has created a room mailbox for roomview using the following configuration.<br>"
$body += "----------------------<br>"
$body += "Name: " + $name + "<br>"
$body += "Alias: " + $alias + "<br>"
$body += "Access group: " + $groupName + "<br>"
#sendMail -address -subject "Roomview Room Creation Script" -body $body -from "roomviewscript@ou.edu" -cc "aheyne@ou.edu"
#-------Cleanup-------#
. updateRVStatus "Done"
$RV_textBox1.Text = ""
$RV_textBox2.Text = ""
} catch {
#--Catch Custom Errors--#
if($error[0].FullyQualifiedErrorId -match "MailboxNotFound"){
. updateRVStatus "Mailbox creation error"
$msg = "The mailbox failed to create."
popupError($msg, 0, "Mailbox creation Error", 0x0)
}
if($error[0].FullyQualifiedErrorId -match "NameValidation"){
. updateRVStatus "Error Validating Room Name"
$msg = "Error Validating Room Name. Resultant name did not match imput."
popupError($msg, 0, "Name Validation Error", 0x0)
}
if($error[0].FullyQualifiedErrorId -match "AliasValidation"){
. updateRVStatus "Error Validating Alias"
$msg = "Error Validating Alias. Resultant alias did not match imput."
popupError($msg, 0, "Alias Validation Error", 0x0)
}
if($error[0].FullyQualifiedErrorId -match "MembershipValidation"){
. updateRVStatus "Error Validating Membership"
$msg = "Error Validating Membership. it_roomview is not a part of the accessgroup."
popupError($msg, 0, "Membership Validation Error", 0x0)
}
if($error[0].FullyQualifiedErrorId -match "InvalidName"){
. updateRVStatus "Invalid Input in Name"
$msg = "Error Validating Name. Name does not conform to naming conventions."
popupError $msg 0 "Invalid Input" 0x0
}
if($error[0].FullyQualifiedErrorId -match "InvalidAlias"){
. updateRVStatus "Invalid Input in Alias"
$msg = "Error Validating Alias. Alias does not conform to naming conventions."
popupError $msg 0 "Invalid Input" 0x0
}
}
}
#endregion Roomview
$OnLoadForm_StateCorrection = {
#Correct the initial state of the form to prevent the .Net maximized form issue
$SCEGUI.WindowState = $InitialFormWindowState
}
#region Form Code
#region Main Window
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 425
$System_Drawing_Size.Width = 660
$SCEGUI.ClientSize = $System_Drawing_Size
$SCEGUI.MaximumSize = $System_Drawing_Size
$SCEGUI.MinimumSize = $System_Drawing_Size
$SCEGUI.MaximizeBox = $false
$SCEGUI.DataBindings.DefaultDataSourceUpdateMode = 0
#$SCEGUI.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon('batman.ico')
$SCEGUI.Name = "SCGUI"
$SCEGUI.Text = "SCGUI"
$SCEGUI.StartPosition = 1
$tabControl1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 0
$System_Drawing_Point.Y = 0
$tabControl1.Location = $System_Drawing_Point
$tabControl1.Name = "tabControl1"
$tabControl1.SelectedIndex = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 388
$System_Drawing_Size.Width = 645
$tabControl1.Size = $System_Drawing_Size
$tabControl1.TabIndex = 0
$SCEGUI.Controls.Add($tabControl1)
#endregion Main Window
#region Create DL
$tabPageDL.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 4
$System_Drawing_Point.Y = 22
$tabPageDL.Location = $System_Drawing_Point
$tabPageDL.Name = "tabPageDL"
$System_Windows_Forms_Padding = New-Object System.Windows.Forms.Padding
$System_Windows_Forms_Padding.All = 3
$System_Windows_Forms_Padding.Bottom = 3
$System_Windows_Forms_Padding.Left = 3
$System_Windows_Forms_Padding.Right = 3
$System_Windows_Forms_Padding.Top = 3
$tabPageDL.Padding = $System_Windows_Forms_Padding
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 362
$System_Drawing_Size.Width = 637
$tabPageDL.Size = $System_Drawing_Size
$tabPageDL.TabIndex = 0
$tabPageDL.Text = "Create DL"
$tabPageDL.UseVisualStyleBackColor = $True
$tabControl1.Controls.Add($tabPageDL)
$groupBox2.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 428
$System_Drawing_Point.Y = 7
$groupBox2.Location = $System_Drawing_Point
$groupBox2.Name = "groupBox2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 168
$System_Drawing_Size.Width = 200
$groupBox2.Size = $System_Drawing_Size
$groupBox2.TabIndex = 13
$groupBox2.TabStop = $False
$groupBox2.Text = "Members"
$tabPageDL.Controls.Add($groupBox2)
$CB_Sponsors.Checked = $True
$CB_Sponsors.CheckState = 1
$CB_Sponsors.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 7
$System_Drawing_Point.Y = 150
$CB_Sponsors.Location = $System_Drawing_Point
$CB_Sponsors.Name = "CB_Sponsors"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 15
$System_Drawing_Size.Width = 187
$CB_Sponsors.Size = $System_Drawing_Size
$CB_Sponsors.TabIndex = 13
$CB_Sponsors.Text = "Add Sponsors?"
$CB_Sponsors.UseVisualStyleBackColor = $True
$groupBox2.Controls.Add($CB_Sponsors)
$RTB_Members.DataBindings.DefaultDataSourceUpdateMode = 0
$RTB_Members.DetectUrls = $False
$RTB_Members.EnableAutoDragDrop = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 7
$System_Drawing_Point.Y = 14
$RTB_Members.Location = $System_Drawing_Point
$RTB_Members.Name = "RTB_Members"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 131
$System_Drawing_Size.Width = 187
$RTB_Members.Size = $System_Drawing_Size
$RTB_Members.TabIndex = 12
$RTB_Members.Text = ""
$groupBox2.Controls.Add($RTB_Members)
$label4.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 152
$System_Drawing_Point.Y = 158
$label4.Location = $System_Drawing_Point
$label4.Name = "label4"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 15
$System_Drawing_Size.Width = 51
$label4.Size = $System_Drawing_Size
#$label4.TabIndex = 12
$label4.Text = "@ou.edu"
$label4.add_Click($handler_label4_Click)
$tabPageDL.Controls.Add($label4)
$RTB_DLOutput.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 6
$System_Drawing_Point.Y = 181
$RTB_DLOutput.Location = $System_Drawing_Point
$RTB_DLOutput.Name = "RTB_DLOutput"
$RTB_DLOutput.ReadOnly = $true
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 175
$System_Drawing_Size.Width = 625
$RTB_DLOutput.Size = $System_Drawing_Size
#$RTB_DLOutput.TabIndex = 11
$RTB_DLOutput.Text = ""
$tabPageDL.Controls.Add($RTB_DLOutput)
$Create.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 330
$System_Drawing_Point.Y = 152
$Create.Location = $System_Drawing_Point
$Create.Name = "Create"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 91
$Create.Size = $System_Drawing_Size
$Create.TabIndex = 14
$Create.Text = "Create"
$Create.UseVisualStyleBackColor = $True
$Create.add_Click($Create_OnClick)
$tabPageDL.Controls.Add($Create)
$ListInGAL.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 219
$System_Drawing_Point.Y = 155
$ListInGAL.Location = $System_Drawing_Point
$ListInGAL.Name = "ListInGAL"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 24
$System_Drawing_Size.Width = 104
$ListInGAL.Size = $System_Drawing_Size
$ListInGAL.TabIndex = 5
$ListInGAL.Text = "List in GAL?"
$ListInGAL.Checked = $true
$ListInGAL.UseVisualStyleBackColor = $True
$tabPageDL.Controls.Add($ListInGAL)
$groupBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 213
$System_Drawing_Point.Y = 7
$groupBox1.Location = $System_Drawing_Point
$groupBox1.Name = "groupBox1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 86
$System_Drawing_Size.Width = 208
$groupBox1.Size = $System_Drawing_Size
$groupBox1.TabIndex = 6
$groupBox1.TabStop = $False
$groupBox1.Text = "Who can send to list?"
$tabPageDL.Controls.Add($groupBox1)
$RB_IO.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 116
$System_Drawing_Point.Y = 50
$RB_IO.Location = $System_Drawing_Point
$RB_IO.Name = "RB_IO"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 30
$System_Drawing_Size.Width = 85
$RB_IO.Size = $System_Drawing_Size
$RB_IO.TabIndex = 9
$RB_IO.TabStop = $True
$RB_IO.Text = "Internal Only"
$RB_IO.UseVisualStyleBackColor = $True
$groupBox1.Controls.Add($RB_IO)
$RB_OO.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 117
$System_Drawing_Point.Y = 20
$RB_OO.Location = $System_Drawing_Point
$RB_OO.Name = "RB_OO"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 30
$System_Drawing_Size.Width = 85
$RB_OO.Size = $System_Drawing_Size
$RB_OO.TabIndex = 8
$RB_OO.TabStop = $True
$RB_OO.Text = "Owners Only"
$RB_OO.UseVisualStyleBackColor = $True