-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUIControls.ps1
1469 lines (1265 loc) · 56.1 KB
/
UIControls.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
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
#===========================================================================
# Forms Functions - used only for this form
#===========================================================================
#region FUNCTION: Builds dynamic variables in form with alias
Function Get-FormVariable{
param(
[string]$Prefix = $WPFVariable,
[Parameter(Mandatory = $true, Position=0)]
[string]$Suffix,
[switch]$Wildcard
)
If($Wildcard){
Return [array]($Global:AllFormVariables | Where Name -like ($Prefix + "_*" + $Suffix + '*')).Value
}
Else{
Return [array]($Global:AllFormVariables | Where Name -eq ($Prefix + "_" + $Suffix)).Value
}
}
#endregion
#Alias to filter function to streamline form call
New-Alias -Name WPFVar -Value Get-FormVariable -Force -ErrorAction SilentlyContinue
#region FUNCTION: Action for Next & back button to change tab
function Switch-TabItem {
param(
[Parameter(Mandatory = $true, Position=0)]
[System.Windows.Controls.TabControl]$TabControlObject,
[Parameter(Mandatory = $true, Position=1,ParameterSetName="index")]
[int]$increment,
[Parameter(Mandatory = $true, Position=1,ParameterSetName="name")]
[string]$name
)
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
If ($PSCmdlet.ParameterSetName -eq "index") {
#Add index number to current tab
$newtab = $TabControlObject.SelectedIndex + $increment
#ensure number is not greater than tabs
If ($newtab -ge $TabControlObject.items.count) {
$newtab=0
}
elseif ($newtab -lt 0) {
$newtab = $TabControlObject.SelectedIndex - 1
}
#Set new tab index
$TabControlObject.SelectedIndex = $newtab
$message = ("index [{0}]" -f $newtab)
}
ElseIf($PSCmdlet.ParameterSetName -eq "name"){
$newtab = $TabControlObject.items | Where Header -eq $name
$newtab.IsSelected = $true
$message = ("name [{0}]" -f $newtab.Header)
}
If($DebugPreference){Write-LogEntry ("Changed to tab {0}" -f $message) -Source ${CmdletName} -Severity 5}
}
#endregion
Function Get-UIFieldElement {
[CmdletBinding()]
param(
[parameter(Mandatory=$true, Position=0,ParameterSetName="name",ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[object[]]$Name
)
Begin{
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
$objects = @()
}
Process{
Foreach($item in $Name){
If($null -ne (Get-FormVariable $item -Wildcard)){
$FieldObject = (Get-FormVariable $item -Wildcard)
$Objects += $FieldObject
If($DebugPreference){Write-LogEntry ("Found field object [{0}]" -f $FieldObject.Name) -Source ${CmdletName} -Severity 5}
}
Else{
If($DebugPreference){Write-LogEntry ("Field object [{0}] does not exist" -f $FieldObject.Name) -Source ${CmdletName} -Severity 5}
}
}
}
End{
Return $Objects
}
}
#region FUNCTION: Set UI fields to either visible and state
Function Set-UIFieldElement {
[CmdletBinding()]
param(
[parameter(Mandatory=$true, Position=0,ParameterSetName="object",ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[object[]]$FieldObject,
[parameter(Mandatory=$true, Position=0,ParameterSetName="name",ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[string[]]$FieldName,
[boolean]$Enable,
[boolean]$Visible,
[string]$Content,
[string]$text,
$Source
)
Begin{
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
#build field object from name
If ($PSCmdlet.ParameterSetName -eq "name")
{
$FieldObject = @()
$FieldObject = Get-UIFieldElement -Name $FieldName
}
#set visable values
switch($Visible)
{
$true {$SetVisible='Visible'}
$false {$SetVisible='Hidden'}
}
}
Process{
Try{
#loop each field object
Foreach($item in $FieldObject)
{
#grab all the parameters
$Parameters = $PSBoundParameters | Select -ExpandProperty Keys
#loop each parameter
Foreach($Parameter in $Parameters)
{
#Determine what each parameter and value is
#if parameter is FieldObject of FieldName ignore setting it value
Switch($Parameter){
'Enable' {$SetValue=$true;$Property='IsEnabled';$value=$Enable}
'Visible' {$SetValue=$true;$Property='Visibility';$value=$SetVisible}
'Content' {$SetValue=$true;$Property='Content';$value=$Content}
'Text' {$SetValue=$true;$Property='Text';$value=$Text}
'Source' {$SetValue=$true;$Property='Source';$value=$Source}
default {$SetValue=$false;}
}
If($SetValue){
# Write-Host ('Parameter value is: {0}' -f $value)
If( $item.$Property -ne $value )
{
$item.$Property = $value
If($DebugPreference){Write-LogEntry ("Object [{0}] {1} property is changed to [{2}]" -f $item.Name,$Property,$Value) -Source ${CmdletName} -Severity 5}
}
Else
{
If($DebugPreference){Write-LogEntry ("Object [{0}] {1} property already set to [{2}]" -f $item.Name,$Property,$Value) -Source ${CmdletName} -Severity 5}
}
}
}#endloop each parameter
}#endloop each field object
}
Catch{
Return $_.Exception.Message
}
}
}
#endregion
Function Enable-TabControl {
param(
[int]$TabNumber,
[switch]$FlipButtons,
[switch]$ReturnActiveBtn
)
#enable Tab
(WPFVar "Tab$TabNumber") | Set-UIFieldElement -Visible:$true
#flip buttons on before tab
If($FlipButtons){
$ButtonNum = $TabNumber
#enable begin for the tab
(WPFVar "btnTab$ButtonNum`Begin") | Set-UIFieldElement -Visible:$True -ErrorAction SilentlyContinue
DO{
If($ButtonNum -gt 1){(WPFVar "btnTab$ButtonNum`Back") | Set-UIFieldElement -Visible:$True -ErrorAction SilentlyContinue}
$ButtonNum--
(WPFVar "btnTab$ButtonNum`Begin") | Set-UIFieldElement -Visible:$False -ErrorAction SilentlyContinue
(WPFVar "btnTab$ButtonNum`Next") | Set-UIFieldElement -Visible:$true -ErrorAction SilentlyContinue
} Until ($ButtonNum -eq 1)
}
if($ReturnActiveBtn){
return (WPFVar "Tab$TabNumber`Begin")
}
}
#endregion
#region FUNCTION: Enable app tab for singlepage
Function Enable-AppTab {
param(
[int]$TabNumber = 2,
[switch]$FlipButtons,
[switch]$ReturnActiveBtn
)
#enable Tab
(WPFVar "Tab$TabNumber") | Set-UIFieldElement -Visible:$true
#getfirsttab
$MainTab = $TabNumber - 1
#flip buttons on before tab
If($FlipButtons){
#enable begin for the tab
(WPFVar "btnTab$TabNumber`Begin") | Set-UIFieldElement -Visible:$True
(WPFVar "btnTab$TabNumber`Back") | Set-UIFieldElement -Visible:$True
(WPFVar "btnTab$MainTab`Begin") | Set-UIFieldElement -Visible:$False
(WPFVar "btnTab$MainTab`Next") | Set-UIFieldElement -Visible:$True
#Allow to navigate the tabs with buttons
(WPFVar "btnTab$TabNumber`Back").Add_Click({Switch-TabItem -Tab (WPFVar "TabControl") -increment -1})
(WPFVar "btnTab$MainTab`Next").Add_Click({Switch-TabItem -Tab (WPFVar "TabControl") -increment 1})
}
if($ReturnActiveBtn){
return (WPFVar "btnTab$TabNumber`Begin")
}
}
#endregion
#region FUNCTION: Disable app tab for singlepage
Function Disable-AppTab {
param(
[int]$TabNumber = 2,
[switch]$FlipButtons,
[switch]$ReturnActiveBtn
)
#enable Tab
(WPFVar "Tab$TabNumber") | Set-UIFieldElement -Visible:$false
#getfirsttab
$MainTab = $TabNumber - 1
#flip buttons on before tab
If($FlipButtons){
#enable begin for the tab
(WPFVar "btnTab$TabNumber`Begin") | Set-UIFieldElement -Visible:$false
(WPFVar "btnTab$TabNumber`Back") | Set-UIFieldElement -Visible:$false
(WPFVar "btnTab$MainTab`Begin") | Set-UIFieldElement -Visible:$True
(WPFVar "btnTab$MainTab`Next") | Set-UIFieldElement -Visible:$False
}
if($ReturnActiveBtn){
return (WPFVar "btnTab$MainTab`Begin")
}
}
#endregion
#region FUNCTION: Update app page with applicatons from config
Function Add-AppContent {
param($AppData)
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
$a = 0
#grab the data & build content from it
Do {
$a++
$App = $AppData | Where {$_.id -eq $a}
If($App){
If($VerbosePreference){Write-LogEntry ("Updating App [{0}] to [{1}]" -f (WPFVar "txtAppName_$($App.id)").Text,$App.Name) -Source ${CmdletName}}
(WPFVar "tglAppInstall_$($App.id)").Visibility = 'Visible'
(WPFVar "txtAppName_$($App.id)").Text = $App.Name
If($App.DefaultEnabled -eq 'Yes'){
(WPFVar "tglAppInstall_$($App.id)").IsChecked = $True
Write-LogEntry ("Enabled App [{0}] by default" -f ${CmdletName},$App.Name) -Source ${CmdletName} -Severity 4
}
Else{
(WPFVar "tglAppInstall_$($App.id)").IsChecked = $False
}
If($App.Desc){
(WPFVar "txtAppDesc_$($App.id)").Visibility = 'Visible'
(WPFVar "txtAppDesc_$($App.id)").Text = $App.Desc
}
Else{
(WPFVar "txtAppDesc_$($App.id)").Visibility = 'Hidden'
}
#$OOBEUIWPF_tglAppInstall_1.IsChecked
}
} Until ($a -eq 8) #end data loop
}
#endregion
#region FUNCTION: pre-populate all time zones in dropdown
Function Add-UITimeZoneList{
param(
$TZCsvList = "$ResourcePath\TimeZonesIndex.csv",
[Parameter(Mandatory = $true, Position=0)]
$TimeZoneField,
[switch]$ReturnList
)
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
#Get all timezones and format the properties
If(Test-Path $TZCsvList -ErrorAction SilentlyContinue){
$TZList = Import-Csv $TZCsvList -ErrorAction Stop | Select Index,TimeZone,@{l='StandardName';e={($_.TimeZone -replace '^.?\((.*?)\)','').Trim()}},UTC
}Else{
$TZList = Get-TimeZone -ListAvailable | Select @{l='TimeZone';e='DisplayName'},StandardName,@{l='UTC';e={$_.DisplayName -match ".?\((.*?)\).*" | Out-Null;$matches[1]}}
}
# populate it to combo box
$TZList.TimeZone | ForEach-object {$TimeZoneField.Items.Add($_);
If($VerbosePreference){Write-LogEntry ("Adding timezone to selection list: {0}" -f $_) -Source ${CmdletName} -Severity 1}} | Out-Null
If($ReturnList){
return $TZList
}
}
#endregion
#region FUNCTION: pre-populate all domain FQDN in dropdown
Function Add-UIDomainNameList{
param(
[Parameter(Mandatory = $true, Position=0)]
[object[]]$DomainList,
[Parameter(Mandatory = $true, Position=1)]
$DomainNameField,
[string]$TypeFilter
)
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
#pre-populate all domain FQDN in dropdown
$DomainList | Where Type -ne $TypeFilter | ForEach-object {$DomainNameField.Items.Add($_);
If($VerbosePreference){Write-LogEntry ("Adding domains to selection list: {0}" -f $_) -Source ${CmdletName} -Severity 1}} | Out-Null
}
#endregion
#region FUNCTION: pre-populate all Sites in dropdown
Function Add-UISiteList{
param(
[Parameter(Mandatory = $true, Position=0)]
$SiteList,
[Parameter(Mandatory = $false, Position=1)]
$SiteListField,
[string]$DisplayFormat = '<id> - <Baselocation> [<SiteCode>]',
[switch]$ReturnList
)
Begin{
## Get the name of this function
[string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
#capture display format to ensure it doesn't get overwritten
$DisplayReset = $DisplayFormat.ToLower()
#test
#$item = @{id='BRGG';Baselocation='FortBragg, nc';SiteCode='BRG'}
#$SiteList = $MenuLocaleSiteList
$DisplayName = @()
}
Process{
Write-LogEntry ("Processing {0} sites" -f $SiteList.Count) -Source ${CmdletName} -Severity 4
#loop through each site
Foreach($site in $SiteList)
{
If($VerbosePreference){Write-LogEntry ("Processing {0} site..." -f $site.ID) -Source ${CmdletName} -Severity 4}
#loop through each property
foreach($property in $Site.PsObject.Properties){
$Name = $property.Name.ToLower()
$Value = $property.Value
If($VerbosePreference){Write-LogEntry ("Searching Property [{0}] with value [{1}] against display format [{2}]" -f $Name,$Value,$DisplayFormat.ToLower()) -Source ${CmdletName} -Severity 4}
If($DisplayFormat.ToLower() -match "<$Name>"){
#build display format with new values
$DisplayFormat = $DisplayFormat -replace $Matches[0],$Value
If($VerbosePreference){Write-LogEntry ("Matched property [{0}] with display format part [{1}], replaced with value [{2}]" -f $Name,$Matches[0],$Value) -Source ${CmdletName} -Severity 4}
}
Else{
$Matches = $null
If($VerbosePreference){Write-LogEntry ("Display format does not match property [{0}]" -f $Name) -Source ${CmdletName} -Severity 4}
Continue;
}
}
#Build display name list
$DisplayName += $DisplayFormat.Trim()
#reset display back to original, then repeat for each site
$DisplayFormat = $DisplayReset
}
#populate site list
$DisplayName | ForEach-object {$SiteListField.Items.Add($_);
If($VerbosePreference){Write-LogEntry ("Adding Site Id's to selection list: {0}" -f $_) -Source ${CmdletName} -Severity 1} } | Out-Null
}
End{
If($ReturnList){
return $DisplayName
}
}
}
#endregion
#region FUNCTION: Update WPF Fields using site ID Selection
Function Update-UILocaleFields {
<#
$SiteList=$MenuLocaleSiteList
$SiteID=$SiteInfo.SiteID
$UpdateSiteListObject=(WPFVar "inputCmbSiteList")
$UpdateTimeZoneObject=(WPFVar "inputCmbTimeZoneList")
$UpdateSiteCodeObject=(WPFVar "txtSiteCode")
$UpdateDomainObject=(WPFVar "inputCmbDomainWorkgroupName")
$ReturnProperties=$true
#>
param(
[Parameter(Mandatory = $false, Position=0)]
[object[]]$SiteList,
[Parameter(Mandatory = $false, Position=1,ParameterSetName="site")]
[string]$SiteID,
[Parameter(Mandatory = $false, Position=1,ParameterSetName="base")]
[string]$Base,
$UpdateSiteListObject,
$UpdateTimeZoneObject,
[System.Windows.Controls.TextBox]$UpdateSiteCodeObject,
#[System.Windows.Controls.TextBox]$UpdateDomainObject,
$UpdateDomainObject,
[switch]$ReturnProperties
)
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
If ($PSCmdlet.ParameterSetName -eq "site") {
$MemberProperty = 'ID'
$SearchCriteria = $SiteID
$MessageSubject = "Site Id"
}
If($PSCmdlet.ParameterSetName -eq "base"){
$MemberProperty = 'BaseLocation'
$SearchCriteria = $Base
$MessageSubject = "Base Location"
}
$MatchedLocale = $null
Write-LogEntry ("Searching for {0} [{1}]" -f $MessageSubject,$SearchCriteria) -Source ${CmdletName}
Try{
#get current site list (from config) where the name matches
$MatchedLocale = $SiteList | Where {$_.$MemberProperty -eq $SearchCriteria}
#if site exists in list
If($null -ne $MatchedLocale){
#Update the Site field by search criteria
$UpdateSiteListObject.SelectedItem = ($UpdateSiteListObject.Items | Where {$_ -match $SearchCriteria})
$UpdateSiteListObject.Items.Refresh();
If($VerbosePreference){Write-LogEntry ("Found match site from locale list: {0}" -f $MatchedLocale.BaseLocation) -Source ${CmdletName}}
#grab the current time based on abbreviation
$TimeZoneBySite = ConvertFrom-TimeZoneAbbreviation -abbr $MatchedLocale.TZ -Country $MatchedLocale.Region
Write-LogEntry ("Time Zone abbreviation found [{0}], selecting time zone: [{1}]" -f $MatchedLocale.TZ,$TimeZoneBySite.FullTZName) -Source ${CmdletName}
$UpdateTimeZoneObject.SelectedItem = $TimeZoneBySite.FullTZName
#$MatchedLocale.Domain
#$UpdateDomainObject.Text = $MatchedLocale.Domain
#update site code
$UpdateSiteCodeObject.text = $MatchedLocale.SiteCode
}
Else{
Write-LogEntry ("No site match was found from locale list using search criteria: {0} [{1}]" -f $MessageSubject,$SearchCriteria) -Source ${CmdletName} -Severity 3
}
}
Catch{
If($VerbosePreference){Write-LogEntry ("No {0} [{1}] found, Breaking search..." -f $MessageSubject,$SearchCriteria) -Source ${CmdletName}}
}
Finally{
If($MatchedLocale -and $ReturnProperties){
$outputObject = New-Object -TypeName PSObject
$memberParam=@{
InputObject=$outputObject;
MemberType='NoteProperty';
Force=$true;
}
Add-Member @memberParam -Name SiteCode -Value $MatchedLocale.SiteCode
Add-Member @memberParam -Name TimeZoneDisplay -Value $TimeZoneBySite.FullTZName
Add-Member @memberParam -Name TimeZoneOSDName -Value $TimeZoneBySite.TZName
Add-Member @memberParam -Name Domain -Value $MatchedLocale.Domain
If($DebugPreference){Write-LogEntry ("Sitecode: [{0}], TimeZoneDisplay: [{1}], TimeZoneOSDName: [{2}], Domain: [{3}]" `
-f $outputObject.SiteCode,$TimeZoneBySite.FullTZName,$TimeZoneBySite.TZName,$MatchedLocale.Domain) -Source ${CmdletName} -Severity 5}
$outputObject
}
}
}
#endregion
#region FUNCTION: Updates domain based on classification
Function Update-UIDomainFields{
param(
$SiteList = $MenuLocaleSiteList,
$ClassificationList = $MenuLocaleClassificationList,
$DomainList = $MenuLocaleDomainList,
$DomainOUlist = $MenuLocaleDomainOUList,
[string]$FilterDomainType = $MenuFilterAccountDomainType,
[string]$FilterDomainProperty = $MenuFilterDomainProperty,
[string]$ClassificationProperty,
[string]$FilterLocale,
[string]$FilterClass,
[bool]$WorkgroupOption
)
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
#split Class value from name into array to determine if a word matches the same from the classification list
$FoundClassMark = (Compare-Object -ReferenceObject $ClassificationList.Type -DifferenceObject ($FilterClass -split '\s') -IncludeEqual -ExcludeDifferent).InputObject
#Identify the current classification Type
$identifiedClass = $ClassificationList | Where {$_.Type -eq $FoundClassMark}
#get current site list (from config) where the name matches
$SiteDomain = $SiteList | Where {$_.BaseLocation -eq $FilterLocale}
Write-LogEntry ("Searching [{0}] to determine domain details..." -f $FilterLocale) -Source ${CmdletName}
#filter to just classification type Domains
#dynamically append filter domain type if value exists
If($FilterDomainProperty){$filterParam = [scriptblock]::Create("`$_.$FilterDomainProperty -eq `$identifiedClass.ID")}
#build scriptblock for domain type
If ($FilterDomainType) {
$filterDomainParam = [scriptblock]::Create(" -and `$_.Type -ne `$FilterDomainType")
$filterParam = [scriptblock]::Create($filterParam.ToString() + $filterDomainParam.ToString())
}
#if a filter exist, use it...
If($filterParam){
$FilteredDomains = $DomainList | Where-Object -FilterScript $filterParam
}
Else{
$FilteredDomains = $DomainList
}
#Add workgroup if allowed
If([bool]$WorkgroupOption)
{
$FilteredDomains += [PSCustomObject]@{Name='Workgroup';FQDN='Workgroup';Classid=$identifiedClass.ID;Type="Join"}
}
#poupulate all domain FQDN in dropdown based on classisification
(WPFVar "inputCmbDomainWorkgroupName").Items.Clear();
$FilteredDomains.FQDN | ForEach-object {(WPFVar "inputCmbDomainWorkgroupName").Items.Add($_);} | Out-Null
#identify the filtered domain details associated with site ID domain
$DomainDetails = $FilteredDomains | Where Name -eq $SiteDomain.Domain
If($DomainDetails)
{
Write-LogEntry ("Found FQDN [{2}] that matched [{0}] under classification [{1}]" -f $SiteDomain.Domain,$identifiedClass.ID,$DomainDetails.FQDN) -Source ${CmdletName} -Severity 4
#update domain FQDN dropdown
(WPFVar "inputCmbDomainWorkgroupName").SelectedItem = $DomainDetails.FQDN
#update Join to Domain Field to FQDN
(WPFVar "inputTxtDomainWorkgroupName").text = $DomainDetails.FQDN
#populate domain name for Domain account
If($FilterDomainType) {
Write-LogEntry ("Filtering domain by classification [{0}] & type [{1}]" -f $identifiedClass.ID,$FilterDomainType) -Source ${CmdletName} -Severity 4
$filterQuery = "`$_.ClassId -eq `$identifiedClass.ID -and `$_.Type -eq `$FilterDomainType"
$filterParam = [scriptblock]::Create($filterQuery)
$DomainDetails = $DomainList | Where-Object -FilterScript $filterParam | Select -First 1
If($DomainDetails){If($VerbosePreference){Write-LogEntry ("Found domain [{0}]" -f $DomainDetails.FQDN) -Source ${CmdletName}}}
}
#grab current value & just replace the domain value before \
$CurrentUserValue = (WPFVar "inputTxtDomainAdminLocalAccount").text
$OldDomain = [regex]::Match($CurrentUserValue,'^[^\\]*').Value
If(!$OldDomain){$AddSlash = '\'}Else{$AddSlash = ''}
#replace domain with new domain
(WPFVar "inputTxtDomainAdminLocalAccount").text = $DomainDetails.Name + '\'
(WPFVar "inputTxtDomainAdminLocalAccount").Foreground = 'Black'
#clear items out first
(WPFVar "inputCmbDomainOU").Items.Clear();
#filter domain OU based on domain name & classification
$FilteredDomainOU = $DomainOUlist | Where {($_.Domain -eq $SiteDomain.Domain) -and ($_.ClassId -eq $identifiedClass.ID)}
#Populate Domain OU's if found
If($FilteredDomainOU){
Foreach($item in $FilteredDomainOU){
$OUdisplayname = $item.Name + ' (' + $item.LDAPOU +')'
(WPFVar "inputCmbDomainOU").Items.Add($OUdisplayname) | Out-Null
If($VerbosePreference){Write-LogEntry ("Adding OU to List: {0}" -f $OUdisplayname) -Source ${CmdletName}}
}
}
#show the classification color
If( ($ClassificationProperty -eq 'None') -or ([string]::IsNullOrEmpty($ClassificationProperty)) ){
# do nothing
}
Else{
#update classification dropdown/textbox
(WPFVar "txtClassification").Text = ($identifiedClass.$ClassificationProperty)
(WPFVar "grdClassification").Visibility = 'Visible'
(WPFVar "txtClassification").IsReadOnly = $true
(WPFVar "txtClassification").Background = $identifiedClass.Color
If($VerbosePreference){Write-LogEntry ("Adding Classification to List: {0}" -f ($identifiedClass.$ClassificationProperty)) -Source ${CmdletName}}
}
}
Else
{
Write-LogEntry ("No Full Qualified Domains Names were found that matched [{0}] under classification [{1}]" -f $SiteDomain.Domain,$identifiedClass.ID) -Source ${CmdletName} -Severity 3
}
}
#endregion
#region FUNCTION: grabs the computer name based on site selection
Function Get-ComputerNameLocale{
param(
[System.Windows.Controls.TextBox]$ComputerNameObject,
$SiteList,
[switch]$ReturnDetails
)
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
If( $ComputerNameObject.Text -match ($SiteList.ID -join '|') ){
$SiteID = $Matches[0]
#get starting position of site code and length of site id
$CharPosition = ($ComputerNameObject.Text | Select-String $SiteID).Matches.Index
$SiteIDLength = $SiteID.Length
#updates the identity locale as well
$BaseLocation = ($SiteList | Where ID -eq $SiteID).BaseLocation
#If($IDFieldObject)
#{
$BaseLocation = ($SiteList | Where ID -eq $SiteID).BaseLocation
#}
}
If($ReturnDetails){
$outputObject = New-Object -TypeName PSObject
$memberParam=@{
InputObject=$outputObject;
MemberType='NoteProperty';
Force=$true;
}
# what to return? If validation is false;
# return that no mater what, otherwise return what specified
Add-Member @memberParam -Name 'CharPosition' -Value $CharPosition
Add-Member @memberParam -Name 'SiteIDLength' -Value $SiteIDLength
Add-Member @memberParam -Name 'SiteID' -Value $SiteID
Add-Member @memberParam -Name 'BaseLocation' -Value $BaseLocation
return $outputObject
}
}
#endregion
#region FUNCTION: Updates the computer name based on site selection
Function Update-ComputerNameLocale{
param(
$SiteList,
$SiteLocale,
[System.Windows.Controls.TextBox]$ComputerNameObject = (WPFVar "inputTxtComputerName"),
[System.Windows.Controls.TextBox]$IDFieldObject = (WPFVar 'txtID3'),
$StartPosition,
[bool]$UpdateComputeName,
[switch]$ReturnSiteInfo
)
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
<# Test Data
$SiteList=$MenuLocaleSiteList
$SiteLocale=(WPFVar "inputCmbSiteList").SelectedItem
$StartPosition=$Global:ComputerNameDetails.CharPosition
$UpdateComputeName=$True
$ReturnSiteInfo=$True
#>
#parse out the site ID from Site Locale (-)
$NewSiteID = $SiteLocale.Split('-')[0].Trim()
#get starting position of site code and length of site id
If($null -ne $StartPosition){
$CharPosition = $StartPosition
}Else{
$CharPosition = ($ComputerNameObject.Text | Select-String $NewSiteID).Matches.Index
}
$SiteIDLength = $NewSiteID.Length
#if the computername is at least 6 chars long.
If( ($ComputerNameObject.Text).Length -gt ($CharPosition + $SiteIDLength))
{
$CurrentSiteID = ($ComputerNameObject.Text).Substring($CharPosition,$SiteIDLength)
If($UpdateComputeName)
{
$ComputerNameObject.Text = $ComputerNameObject.Text -replace $CurrentSiteID,$NewSiteID
If($DebugPreference){Write-LogEntry ("Updated device name site locale from [{0}] to [{1}]" -f $CurrentSiteID,$NewSiteID) -Source ${CmdletName} -Severity 5}
}
}
#updates the identity locale as well
If($IDFieldObject)
{
$BaseLocation = ($SiteList | Where ID -eq $NewSiteID).BaseLocation
$IDFieldObject.text = $BaseLocation
}
If($ReturnSiteInfo){
$outputObject = New-Object -TypeName PSObject
$memberParam=@{
InputObject=$outputObject;
MemberType='NoteProperty';
Force=$true;
}
# what to return? If validation is false;
# return that no mater what, otherwise return what specified
Add-Member @memberParam -Name 'SiteID' -Value $NewSiteID
Add-Member @memberParam -Name 'BaseLocation' -Value $BaseLocation
return $outputObject
}
}
#endregion
#region FUNCTION: Updates the computer name based on site selection
#NOT USED. Testing...
Function Compare-ComputerNameLocale{
param(
$SiteList = $MenuLocaleSiteList,
[Parameter(Mandatory, Position=0, ParameterSetName="Locale")]
[string]$UpdateSiteLocaleTo,
[Parameter(Mandatory, Position=0, ParameterSetName="ID")]
[string]$UpdateSiteIdTo,
[Parameter(Mandatory, Position=1, ParameterSetName="Locale")]
[string]$CurrentSiteLocale,
[Parameter(Mandatory, Position=1, ParameterSetName="ID")]
[string]$CurrentSiteID,
[int]$StartPosition,
[System.Windows.Controls.TextBox]$ComputerNameObject = (WPFVar "inputTxtComputerName"),
[System.Windows.Controls.TextBox]$IDFieldObject = (WPFVar 'txtID3')
)
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
#grab the current computername
$CurrentComputerName = $ComputerNameObject.Text
#parse out the site ID from Site Locale seelected
if($PSCmdlet.ParameterSetName -eq "Locale"){
$NewSiteID = ($UpdateSiteLocaleTo -split '-')[0].Trim()
#$NewSiteID = [Regex]::Match($SiteLocale,".{1,$SiteIDLength}").Value
$OldSiteID = ($CurrentSiteLocale -split '-')[0].Trim()
}
If($PSCmdlet.ParameterSetName -eq "ID"){
$NewSiteID = $UpdateSiteIdTo
$OldSiteID = $CurrentSiteID
}
Write-LogEntry ("Comparing device name [{0}] to SiteID [{1}]" -f $CurrentComputerName,$NewSiteID) -Source ${CmdletName} -Severity 4
#if the computername is at least 6 chars long.
#If($CurrentComputerName.Length -gt $NewSiteID.Length)
If($CurrentComputerName -notmatch $NewSiteID)
{
#$CurrentSiteID = ($ComputerNameObject.Text).Substring(2,$NewSiteID.Length)
$ComputerNameObject.Text = $CurrentComputerName -replace $OldSiteID,$NewSiteID
$ComputerNameObject.Text.Refresh();
Write-LogEntry ("Updated device name site locale from [{0}] to [{1}]" -f $OldSiteID,$NewSiteID) -Source ${CmdletName} -Severity 4
}
Else{
Write-LogEntry ("Device name [{0}] matches Site ID [{1}]" -f $CurrentComputerName,$NewSiteID) -Source ${CmdletName} -Severity 4
}
#updates the identity locale as well
If($IDFieldObject)
{
Write-LogEntry ("Searching location identifier for Site ID [{0}]" -f $SiteID) -Source ${CmdletName} -Severity 4
$BaseLocation = ($SiteList | Where ID -eq $NewSiteID).BaseLocation
$IDFieldObject.text = $BaseLocation
Write-LogEntry ("Updated location identifier [{0}] to [{1}]" -f $IDFieldObject.Name,$BaseLocation) -Source ${CmdletName} -Severity 4
}
}
#endregion
#region FUNCTION: Removed highlights border on objects
Function Reset-HighlightedFields {
param($Object,[switch]$ClearErrorMessage)
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
If($ClearErrorMessage){
Invoke-UIMessage -Message $Null -OutputErrorObject (WPFVar "txtError") -Type Info
}
Try{
Foreach($item in $Object){
If($item.BorderThickness.Bottom -gt 0)
{
$item.BorderThickness = "0"
If($DebugPreference){Write-LogEntry ("Object [{0}] was reset" -f ${CmdletName},$item.Name) -Source ${CmdletName} -Severity 5}
}
Else{
If($DebugPreference){Write-LogEntry ("Object [{0}] did not need reset" -f ${CmdletName},$item.Name) -Source ${CmdletName} -Severity 5}
}
}
}Catch{}
}
#endregion
#region FUNCTION: Clears the other fields in UI
Function Clear-UIField {
param(
[string]$Name,
[ValidateSet('Input', 'List', 'Grid','label')]
[string]$Type,
[switch]$Hide
)
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
#get each WPF object that matches the id
$UIFieldName = WPFVar $Name -Wildcard
Switch($Type){
'Input' {$property = 'Text'}
'List' {$property = 'Content'}
'Grid' {$property = 'Grid'}
'label' {$property = 'Content'}
}
If($UIFieldName){
Try{
#clear value
$UIFieldName.$property = ''
}
Catch{
}
Finally{
#if set, hide the label & value block
If($Hide)
{
$UIFieldName.Visibility = 'Hidden'
If($DebugPreference){Write-LogEntry ("Cleared & Hide field: [{0}]" -f $UIFieldName.Name) -Source ${CmdletName} -Severity 5}
}
Else{
If($DebugPreference){Write-LogEntry ("Cleared field: [{0}]" -f $UIFieldName.Name) -Source ${CmdletName} -Severity 5}
}
}
}
}
#endregion
#region FUNCTION: Flips Combobox to Textbox (only suppos like fields)
Function ConvertTo-UITextBox{
param(
[System.Windows.Controls.ComboBox]$ComboBox
)
$ConvertCmbtoTxt = $ComboBox.Name -replace 'cmb','txt'
(WPFVar $ComboBox.Name) | Set-UIFieldElement -Visible:$False
If((WPFVar $ConvertCmbtoTxt))
{
(WPFVar $ConvertCmbtoTxt) | Set-UIFieldElement -Visible:$True
}
}
#endregion
#region FUNCTION: Flips Textbox to Combobox (only suppos like fields)
Function ConvertTo-UIComboBox{
param(
[System.Windows.Controls.TextBox]$TextBox
)
$ConvertTxtToCmb = $TextBox.Name -replace 'txt','cmb'
(WPFVar $TextBox.Name) | Set-UIFieldElement -Visible:$False
If((WPFVar $ConvertTxtToCmb))
{
(WPFVar $ConvertTxtToCmb) | Set-UIFieldElement -Visible:$True
}
}
#endregion
#region FUNCTION: Clears the Identify information in UI
Function Clear-UIIdentityFields {
param(
$IDList = $NameStandardRuleSets,
[switch]$Hide
)
#loop through each ID
Foreach($item in $IDList)
{
#get each WPF object that matches the id
$UIFieldName = WPFVar ('txt' + $item.id) -Wildcard
$UIFieldLabel = WPFVar ('lbl' + $item.id) -Wildcard
#clear value
$UIFieldName.Text = ''
#if the value is null, just display ID as value
If([string]::IsNullOrEmpty($UIFieldName.Text)){$FieldValue = $item.id}Else{$FieldValue = $UIFieldName.text}
#if set, hide the label & value block
If($Hide)
{
$UIFieldLabel.Visibility = 'Hidden'
$UIFieldName.Visibility = 'Hidden'
If($DebugPreference){Write-LogEntry ("Cleared & Hide field: [{0}]" -f $FieldValue) -Source ${CmdletName} -Severity 5}
}
Else{
If($DebugPreference){Write-LogEntry ("Cleared field: [{0}]" -f $FieldValue) -Source ${CmdletName} -Severity 5}
}
} #end loop of ID's
}
#endregion
#region FUNCTION: updates the Identify information in UI
Function Update-UIIdentityFields {
param(
$RulesList = $NameStandardRuleSets,
$FieldsTable,
[switch]$ClearValues
)
## Get the name of this function
[string]${CmdletName} = $MyInvocation.MyCommand
#clear all identity rules
If($ClearValues){Clear-UIIdentityFields -Hide}
$objMembers = $FieldsTable.psobject.members | where-object membertype -like 'noteproperty'
#create an empty hashtable to add objects to.
$HashTable = @{}
foreach ($obj in $objMembers) {
$HashTable.add( "$($obj.name)", "$($obj.Value)")
}
#parse thehashtable
Foreach($item in $HashTable.Keys){
Try{
#grab the key
$UIFieldlabel = WPFVar ('lbl' + $item) -Wildcard
$UIFieldText = WPFVar ('txt' + $item) -Wildcard
#grab the value
$UIFieldValue = $HashTable.Item($item)
#grab name from rule
$RuleSet = ($RulesList | Where Id -eq $item)
$UIFieldlabelName = $RuleSet.Name
[Boolean]$MustExist = [Boolean]::Parse($RuleSet.MustExist)
#populate label if required (even though it may be empty)
If($MustExist){
$UIFieldlabel.Content = $UIFieldlabelName
$UIFieldLabel.Visibility = 'Visible'
}
#if there is a value fill it
If($UIFieldValue)
{
#make sure lbl & txt field are visible
$UIFieldText.Visibility = 'Visible'
$UIFieldlabel.Visibility = 'Visible'
#update display name
$UIFieldlabel.Content = $UIFieldlabelName
$UIFieldText.Text = $UIFieldValue
If($DebugPreference){Write-LogEntry ("Updated field: [{0}: {1}] to [{2}]" -f $item,$UIFieldlabelName,$UIFieldValue) -Source ${CmdletName} -Severity 5}
}
}
Catch{
#just in case there is not field object that exists
}
}
}
#endregion
#region FUNCTION: Throw errors to Form's Output field
Function Invoke-UIMessage {