-
Notifications
You must be signed in to change notification settings - Fork 4
/
OSDOOBEUI.ps1
1339 lines (1188 loc) · 61.9 KB
/
OSDOOBEUI.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
<#
.SYNOPSIS
A PowerShell Driven Single page UI.
.DESCRIPTION
A PowerShell Driven Single page UI that looks and feels like Windows 10 OOBE. Used in SCCM/MDT TaskSequence Bare-metal deployments
.NOTES
Author : Dick Tracy II <[email protected]>
Source : https://github.com/PowerShellCrack/OSDOOBEUI
Version : 2.1.1
#Requires -Version 3.0
IMPORTANT: Review OOBEWPFUI.config for more details and confiugrations
.PARAMETER Config
STRING. Used to identify configuration file;
DEFAULT: to OOBEWPFUI.config
.EXAMPLE
.\OSDOOBEUI_SinglePage.ps1
.EXAMPLE
.\OSDOOBEUI_SinglePage.ps1 -Config OOBEWPFUI.contoso.config
.EXAMPLE
;Call in Task Sequence example
Powershell -ExecutionPolicy Bypass -File %SCRIPTROOT%\Custom\OSDOOBEUI\OSDOOBEUI_SinglePage.ps1 -Config OSDOOBEUI.nmci.config
.LINK
LTIHashCheckUI.ps1
#>
[Cmdletbinding()]
Param (
[Parameter(Mandatory=$False)]
[String]$Config
)
$VerbosePreference = 'SilentlyContinue'
$DebugPreference = 'SilentlyContinue'
#*=============================================
##* Runtime Function - REQUIRED
##*=============================================
#region FUNCTION: Check if running in WinPE
Function Test-WinPE{
return Test-Path -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlset\Control\MiniNT
}
#endregion
#region FUNCTION: Check if running in ISE
Function Test-IsISE {
# try...catch accounts for:
# Set-StrictMode -Version latest
try {
return ($null -ne $psISE);
}
catch {
return $false;
}
}
#endregion
#region FUNCTION: Check if running in Visual Studio Code
Function Test-VSCode{
if($env:TERM_PROGRAM -eq 'vscode') {
return $true;
}
Else{
return $false;
}
}
#endregion
#region FUNCTION: Find script path for either ISE or console
Function Get-ScriptPath {
<#
.SYNOPSIS
Finds the current script path even in ISE or VSC
.LINK
Test-VSCode
Test-IsISE
#>
param(
[switch]$Parent
)
Begin{}
Process{
if ($PSScriptRoot -eq "")
{
if (Test-IsISE)
{
$ScriptPath = $psISE.CurrentFile.FullPath
}
elseif(Test-VSCode){
$context = $psEditor.GetEditorContext()
$ScriptPath = $context.CurrentFile.Path
}Else{
$ScriptPath = (Get-location).Path
}
}
else
{
$ScriptPath = $PSCommandPath
}
}
End{
If($Parent){
Split-Path $ScriptPath -Parent
}Else{
$ScriptPath
}
}
}
#endregion
# Make PowerShell Disappear in WINPE
If(Test-WinPE){
$windowcode = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
$asyncwindow = Add-Type -MemberDefinition $windowcode -name Win32ShowWindowAsync -namespace Win32Functions -PassThru
$null = $asyncwindow::ShowWindowAsync((Get-Process -PID $pid).MainWindowHandle, 0)
}
##*=============================================
##* VARIABLE DECLARATION
##*=============================================
#region VARIABLES: Building paths & values
# Use function to get paths because Powershell ISE & other editors have differnt results
[string]$scriptPath = Get-ScriptPath
[string]$scriptName = [IO.Path]::GetFileNameWithoutExtension($scriptPath)
[string]$scriptRoot = Split-Path -Path $scriptPath -Parent
#Get required folder & File paths
[string]$FunctionPath = Join-Path -Path $scriptRoot -ChildPath 'Functions'
[string]$ResourcePath = Join-Path -Path $scriptRoot -ChildPath 'Resources'
[string]$XAMLPath = Join-Path -Path $ResourcePath -ChildPath 'OOBEUIWPF.xaml'
#*=============================================
##* Additional Runtime Function - REQUIRED
##*=============================================
#Load functions from external files
. "$FunctionPath\Environments.ps1"
. "$FunctionPath\Logging.ps1"
. "$FunctionPath\Accounts.ps1"
. "$FunctionPath\PlatformInfo.ps1"
. "$FunctionPath\InterfaceDetails.ps1"
. "$FunctionPath\RegionLocale.ps1"
. "$FunctionPath\ComputerNameRules.ps1"
. "$FunctionPath\UIControls.ps1"
. "$FunctionPath\SetOSDVariables.ps1"
#Return log path (either in task sequence or temp dir)
#build log name
[string]$FileName = $scriptName +'.log'
#build global log fullpath
$Global:LogFilePath = Join-Path (Test-SMSTSENV -ReturnLogPath -Verbose) -ChildPath $FileName
Write-Host "logging to file: $LogFilePath" -ForegroundColor Cyan
#=======================================================
# PARSE CONFIG FILE
#=======================================================
#region CONFIG: & variables from configuration file
#if config specified, use that, otherwise use default
#TEST: $ConfigPath = 'OOBEUIWPF.nmci.config'
If($PSBoundParameters.ContainsKey('Config'))
{
[string]$ConfigPath = $ConfigPath = $Config
$ConfigLocation = 'Config Param'
}
#variable found in TaskSequence overwrite whats used from script
Elseif($tsenv:UIControl_ConfigFile)
{
[string]$ConfigPath = $tsenv.Value("UIControl_ConfigFile")
$ConfigLocation = 'TS Variable'
}
#otherwise use default
Else{
[string]$ConfigPath = 'OSDOOBEUI.config'
$ConfigLocation = 'Default location'
}
#resolve path to config
$ConfigResolvedFilePath = Resolve-ActualPath -FileName $ConfigPath -WorkingPath $scriptRoot -ErrorAction Stop
Write-LogEntry ("Grabbing Configurations [{0}] from [{1}]" -f $ConfigResolvedFilePath,$ConfigLocation) -Severity 1
[Xml.XmlDocument]$XmlConfigFile = Get-Content $ConfigResolvedFilePath -ErrorAction Stop
# Parse config xml
[Xml.XmlElement]$xmlConfig = $xmlConfigFile.OOBEMenu_Configs
# Get Config File Details
[Xml.XmlElement]$configDetails = $xmlConfig.Menu_Details
[string]$MenuTitle = [string]$configDetails.Detail_Title
[string]$MenuVersion = [string]$configDetails.Detail_Version
[string]$MenuDate = [string]$configDetails.Detail_Date
#parse changelog for version for a more accurate version
$ChangeLogPath = Resolve-ActualPath -FileName 'CHANGELOG.md' -WorkingPath $scriptRoot -ErrorAction SilentlyContinue
If($ChangeLogPath){
$ChangeLog = Get-Content $ChangeLogPath
$Changedetails = (($ChangeLog -match '##')[0].TrimStart('##') -split '-').Trim()
[string]$MenuVersion = [version]$Changedetails[0]
[string]$MenuDate = $Changedetails[1]
}
# Get Menu Options
[Xml.XmlElement]$xmlMenuOptions = $xmlConfig.Menu_Options
[string]$Logo1Position = Test-IsNull $xmlMenuOptions.Option_Logo1Position
[string]$Logo1file = Test-IsNull $xmlMenuOptions.Option_Logo1File
[string]$Logo2Position = Test-IsNull $xmlMenuOptions.Option_Logo2Position
[string]$Logo2file = Test-IsNull $xmlMenuOptions.Option_Logo2File
[string]$WPFVariable = $xmlMenuOptions.Option_FormVariable
[Boolean]$VerboseMode = [Boolean]::Parse($xmlMenuOptions.Option_VerboseMode)
[Boolean]$DebugMode = [Boolean]::Parse($xmlMenuOptions.Option_DebugMode)
[Boolean]$TestMode = [Boolean]::Parse($xmlMenuOptions.Option_TestMode)
[Boolean]$Global:HostOutput = [Boolean]::Parse($xmlMenuOptions.Option_HostOutput)
[string]$BackgroundColor = Test-IsNull $xmlMenuOptions.Option_BackgroundColor
# Get UI Controls
[Xml.XmlElement]$xmlUIControls = $xmlConfig.UI_Controls
[Boolean]$MenuOverWriteUIControlByTS = [Boolean]::Parse($xmlUIControls.Control_OverWriteUIControlByTS)
[Boolean]$MenuShowSplashScreen = [Boolean]::Parse($xmlUIControls.Control_ShowSplashScreen)
[Boolean]$MenuShowSiteCode = [Boolean]::Parse($xmlUIControls.Control_ShowSiteCode)
[Boolean]$MenuShowSiteListSelection = [Boolean]::Parse($xmlUIControls.Control_ShowSiteListSelection)
[Boolean]$MenuShowDomainOUSelection = [Boolean]::Parse($xmlUIControls.Control_ShowDomainOUListSelection)
[Boolean]$MenuEnableNetworkDetection = [Boolean]::Parse($xmlUIControls.Control_EnableNetworkDetection)
[Boolean]$MenuEnableValidateNameRules = [Boolean]::Parse($xmlUIControls.Control_ValidateNameRules)
[Boolean]$MenuAllowCustomDomain = [Boolean]::Parse($xmlUIControls.Control_AllowCustomDomain)
[Boolean]$MenuAllowWorkgroupJoin = [Boolean]::Parse($xmlUIControls.Control_AllowWorkgroupJoin)
[Boolean]$MenuAllowSiteSelection = [Boolean]::Parse($xmlUIControls.Control_AllowSiteSelection)
[Boolean]$MenuHideDomainCreds = [Boolean]::Parse($xmlUIControls.Control_HideDomainCreds)
[Boolean]$MenuHideDomainList = [Boolean]::Parse($xmlUIControls.Control_HideDomainList)
[string[]]$MenuAllowRuleBypassModeKey = $xmlUIControls.Control_AllowRuleBypassModeKey
[string]$MenuFilterAccountDomainType = $xmlUIControls.Control_FilterAccountDomainType
[string]$MenuFilterDomainProperty = $xmlUIControls.Control_FilterDomainProperty
[string]$MenuShowClassificationProperty = $xmlUIControls.Control_ShowClassificationProperty
[string]$MenuGenerateNameMethod = $xmlUIControls.Control_GenerateNameMethod
[string]$MenuGenerateNameSource = $xmlUIControls.Control_GenerateNameSource
#page Selection
[Xml.XmlElement]$xmlUIPages = $xmlConfig.UI_Pages
[Boolean]$MenuShowAppSelection = [Boolean]::Parse($xmlUIPages.Page_ShowAppSelection)
# Get UI Lists
If($null -ne $xmlConfig.Locale_Sites.ExternalList)
{
#grab the first row for column definitions
$MenuLocaleSiteColumns = $xmlConfig.Locale_Sites.site | Select -First 1
#if CSV path is found, import it, otherwise unable to continue
$ExternalCsv = Resolve-ActualPath -FileName $xmlConfig.Locale_Sites.ExternalList -WorkingPath $scriptRoot -ErrorAction Stop
Write-LogEntry ("Grabbing External Site list from [{0}]" -f $ExternalCsv) -Severity 1
$MenuLocaleSiteExternalList = Import-Csv $ExternalCsv -ErrorAction Stop
#convert Site list to object
$MenuLocaleSiteList = $MenuLocaleSiteExternalList | Select-Object -Property `
@{name="ID"; expression={$_.($MenuLocaleSiteColumns | Select -ExpandProperty ID)}},
@{name="BaseLocation"; expression={$_.($MenuLocaleSiteColumns | Select -ExpandProperty BaseLocation)}},
@{name="TZ"; expression={$_.($MenuLocaleSiteColumns | Select -ExpandProperty TZ)}},
@{name="Region"; expression={$_.($MenuLocaleSiteColumns | Select -ExpandProperty Region)}},
@{name="SiteCode"; expression={$_.($MenuLocaleSiteColumns | Select -ExpandProperty SiteCode)}},
@{name="Domain"; expression={$_.($MenuLocaleSiteColumns | Select -ExpandProperty Domain)}}
}
Else{
$MenuLocaleSiteList = $xmlConfig.Locale_Sites.site
$MenuLocaleSiteList = $MenuLocaleSiteList | Select ID,BaseLocation,TZ,Region,SiteCode,Domain
}
# Get Format for Site list
[string]$SiteListFormat = $xmlConfig.Locale_Sites.DisplayFormat
[string]$SiteCodeFormat = $xmlConfig.Locale_Sites.SiteCodeFormat
#build format based on config
If($MenuShowSiteCode -and $SiteCodeFormat){$DisplayFormat = ($SiteListFormat + $SiteCodeFormat) }Else{$DisplayFormat = $SiteListFormat}
$MenuLocaleClassificationList = $xmlConfig.Locale_Classifications.classification
$MenuLocaleDomainList = $xmlConfig.Locale_Domains.Domain
$MenuLocaleDomainOUList = $xmlConfig.Locale_DomainOUs.OU
$MenuLocaleNetworkList = $xmlConfig.Locale_NetworkDetection.network
#get Menu Add Buttons
$MenuAppButtonsItems = $xmlConfig.Menu_AppButtons.item
#get Computer name standard
[Xml.XmlElement]$xmlNameGeneration = $xmlConfig.Name_Generation_Rules
$NameStandardRuleSets = $xmlNameGeneration.rulesets
$NameStandardRuleExampleText = $xmlNameGeneration.Example
#logo images
If($Logo1file){
[string]$Logo1ImgPath = Join-Path -Path $ResourcePath -ChildPath $Logo1file
}
If($Logo2file){
[string]$Logo2ImgPath = Join-Path -Path $ResourcePath -ChildPath $Logo2file
}
#endregion
#Overwrites config menu if running in TS and has variables found
If(Test-SMSTSENV -and $MenuOverWriteUIControlByTS){
# Global Settings
If($tsenv:Debug){
[Boolean]$VerboseMode = [boolean]::Parse($tsenv.Value("Debug"))
[Boolean]$DebugMode = [boolean]::Parse($tsenv.Value("Debug"))
}
If($tsenv:TSDebugMode){
[Boolean]$VerboseMode = [boolean]::Parse($tsenv.Value("TSDebugMode"))
[Boolean]$DebugMode = [boolean]::Parse($tsenv.Value("TSDebugMode"))
}
#controls
If($tsenv:UIControl_MenuShowSplashScreen){[Boolean]$MenuShowSplashScreen = [boolean]::Parse($tsenv.Value("UIControl_MenuShowSplashScreen"))}
If($tsenv:UIControl_ShowSiteCode){[Boolean]$MenuShowSiteCode = [boolean]::Parse($tsenv.Value("UIControl_ShowSiteCode"))}
If($tsenv:UIControl_ShowSiteListSelection){[Boolean]$MenuShowSiteListSelection = [boolean]::Parse($tsenv.Value("UIControl_ShowSiteListSelection"))}
If($tsenv:UIControl_ShowDomainOUListSelection){[Boolean]$MenuShowDomainOUSelection = [boolean]::Parse($tsenv.Value("UIControl_ShowDomainOUListSelection"))}
If($tsenv:UIControl_EnableNetworkDetection){[Boolean]$MenuEnableNetworkDetection = [boolean]::Parse($tsenv.Value("UIControl_EnableNetworkDetection"))}
If($tsenv:UIControl_ValidateNameRules){[Boolean]$MenuEnableValidateNameRules = [boolean]::Parse($tsenv.Value("UIControl_ValidateNameRules"))}
If($tsenv:UIControl_AllowCustomDomain){[Boolean]$MenuAllowCustomDomain = [boolean]::Parse($tsenv.Value("UIControl_AllowCustomDomain"))}
If($tsenv:UIControl_AllowWorkgroupJoin){[Boolean]$MenuAllowWorkgroupJoin = [boolean]::Parse($tsenv.Value("UIControl_AllowWorkgroupJoin"))}
If($tsenv:UIControl_AllowSiteSelection){[Boolean]$MenuAllowSiteSelection = [boolean]::Parse($tsenv.Value("UIControl_AllowSiteSelection"))}
If($tsenv:UIControl_AllowRuleBypassModeKey){[String[]]$MenuAllowRuleBypassModeKey = $tsenv.Value("Control_AllowRuleBypassModeKey")}
If($tsenv:UIControl_FilterAccountDomainType){[string]$MenuFilterAccountDomainType = $tsenv.Value("UIControl_FilterAccountDomainType")}
If($tsenv:UIControl_FilterDomainProperty){[string]$MenuFilterDomainProperty = $tsenv.Value("UIControl_FilterDomainProperty")}
If($tsenv:UIControl_ShowClassificationProperty){[string]$MenuShowClassificationProperty = $tsenv.Value("UIControl_ShowClassificationProperty")}
If($tsenv:UIControl_GenerateNameMethod){[string]$MenuGenerateNameMethod = $tsenv.Value("UIControl_GenerateNameMethod")}
If($tsenv:UIControl_GenerateNameSource){[string]$MenuGenerateNameSource = $tsenv.Value("UIControl_GenerateNameSource")}
#pages
If($tsenv:UIPage_MenuShowAppSelection){[Boolean]$MenuShowAppSelection = [boolean]::Parse($tsenv.Value("UIPage_MenuShowAppSelection"))}
}
#=======================================================
# LOAD ASSEMBLIES
#=======================================================
[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | out-null #creating Windows-based applications
[System.Reflection.Assembly]::LoadWithPartialName('WindowsFormsIntegration') | out-null # Call the EnableModelessKeyboardInterop; allows a Windows Forms control on a WPF page.
[System.Reflection.Assembly]::LoadWithPartialName('System.Windows') | out-null #Encapsulates a Windows Presentation Foundation application.
[System.Reflection.Assembly]::LoadWithPartialName('System.ComponentModel') | out-null #systems components and controls and convertors
[System.Reflection.Assembly]::LoadWithPartialName('System.Data') | out-null #represent the ADO.NET architecture; allows multiple data sources
[System.Reflection.Assembly]::LoadWithPartialName('PresentationFramework') | out-null #required for WPF
[System.Reflection.Assembly]::LoadWithPartialName('PresentationCore') | out-null #required for WPF
#=======================================================
# Splash Screen
#=======================================================
# build a hash table with locale data to pass to runspace
$Global:SplashScreen = [hashtable]::Synchronized(@{})
$Global:SplashScreen.Title = $MenuTitle
$Global:SplashScreen.Logo1Position = $Logo1Position
$Global:SplashScreen.Logo1file = $Logo1ImgPath
$Global:SplashScreen.Logo2Position = $Logo2Position
$Global:SplashScreen.Logo2file = $Logo2ImgPath
$Global:SplashScreen.BGColor = $BackgroundColor
#build runspace
$Script:runspace = [runspacefactory]::CreateRunspace()
$Script:runspace.ApartmentState = "STA"
$Script:runspace.ThreadOptions = "ReuseThread"
$Script:runspace.Open()
$Script:runspace.SessionStateProxy.SetVariable("SplashScreen",$Global:SplashScreen)
$Script:Pwshell = [PowerShell]::Create()
#Create a scripblock with variables from hashtable
$Script:Pwshell.AddScript({
[String]$MenuTitle = $Global:SplashScreen.Title
[String]$Logo1Position = $Global:SplashScreen.Logo1Position
[String]$Logo1File = $Global:SplashScreen.Logo1file
[String]$Logo2Position = $Global:SplashScreen.Logo2Position
[String]$Logo2File = $Global:SplashScreen.Logo2file
[string]$BGColor = $Global:SplashScreen.BGColor
$xml = @"
<Window x:Class="OOBEUI_ForTS.splashscreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OOBEUI_ForTS"
mc:Ignorable="d"
WindowState="Maximized"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
Title="Splashscreen"
Width="1024" Height="768"
Background="#1f1f1f">
<Grid x:Name="background" Background="#004275" VerticalAlignment="Center">
<Grid x:Name="ShowProgressBar" Visibility="Visible" HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="180" Panel.ZIndex="20" >
<Image x:Name="LogoImgLeft" HorizontalAlignment="Left" Margin="30,21,0,0" Width="100" Height="100" VerticalAlignment="Top" />
<StackPanel Orientation="Vertical" Width="500" HorizontalAlignment="Center" VerticalAlignment="Center">
<Label x:Name="LogoLabel" Foreground="White" Height="70" FontSize="50" Margin="5,0,0,0" />
<ProgressBar x:Name="ProgressBar" Height="20" HorizontalAlignment="Stretch" Foreground="White" VerticalAlignment="Top" Margin="10,10,10,10"/>
<Label x:Name="ProgressLabel" Content=" " Foreground="White" FontSize="16" Width="300" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,10,0"/>
</StackPanel>
<Image x:Name="LogoImgRight" HorizontalAlignment="Right" Margin="0,21,30,0" Width="100" Height="100" VerticalAlignment="Top" />
</Grid>
</Grid>
</Window>
"@
$SplashXml = $xml -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
If($Global:SplashScreen.BGColor){$SplashXml = $SplashXml -replace 'Background="#004275"', "Background=`"$BGColor`""}
[xml]$XAML = $SplashXml
$reader = New-Object System.Xml.XmlNodeReader ([xml]$XAML)
$Global:SplashScreen.window = [Windows.Markup.XamlReader]::Load($reader)
$Global:SplashScreen.ProgressBar = $Global:SplashScreen.window.FindName("ProgressBar")
$Global:SplashScreen.ProgressLabel = $Global:SplashScreen.window.FindName("ProgressLabel")
$Global:SplashScreen.LogoLabel = $Global:SplashScreen.window.FindName("LogoLabel")
$Global:SplashScreen.LogoImgLeft = $Global:SplashScreen.window.FindName("LogoImgLeft")
$Global:SplashScreen.LogoImgRight = $Global:SplashScreen.window.FindName("LogoImgRight")
If( $Logo1File -and ( ($null -ne $Logo1Position) -or ($Logo1Position -ne 'hidden' )) ){
If(Resolve-Path $Logo1File -ErrorAction SilentlyContinue)
{
switch($Logo1Position){
'Left' {
$LogoLeftVisible='Visible'
$Global:SplashScreen.LogoImgLeft.Source = $Logo1file
}
'Right' {
$LogoRightVisible='Visible'
$Global:SplashScreen.LogoImgRight.Source = $Logo1file
}
'Both' {
$LogoLeftVisible='Visible'
$Global:SplashScreen.LogoImgLeft.Source = $Logo1file
$LogoRightVisible='Visible'
$Global:SplashScreen.LogoImgRight.Source = $Logo1file
}
default {
$LogoLeftVisible='Visible'
If($Logo2Position -ne 'both'){$Global:SplashScreen.LogoImgLeft.Source = $Logo1file}
}
}
}
}
If($Logo2File -and ( ($null -ne $Logo2Position) -or ($Logo2Position -ne 'hidden' )) ){
If(Resolve-Path $Logo2File -ErrorAction SilentlyContinue)
{
switch($Logo2Position){
'Left' {
$LogoLeftVisible='Visible'
$Global:SplashScreen.LogoImgLeft.Source = $Logo2file
}
'Right' {
$LogoRightVisible='Visible'
$Global:SplashScreen.LogoImgRight.Source = $Logo2file
}
'Both' {
$LogoLeftVisible='Visible'
$Global:SplashScreen.LogoImgLeft.Source = $Logo2file
$LogoRightVisible='Visible'
$Global:SplashScreen.LogoImgRight.Source = $Logo2file
}
default {
$LogoRightVisible='Visible'
If($Logo1Position -ne 'both'){$Global:SplashScreen.LogoImgRight.Source = $Logo2file}
}
}
}
}
$Global:SplashScreen.LogoImgLeft.Visibility = $LogoLeftVisible
$Global:SplashScreen.LogoImgRight.Visibility = $LogoRightVisible
$Global:SplashScreen.LogoLabel.Content = $MenuTitle
#make sure this display on top of every window
$Global:SplashScreen.window.Topmost = $true
$Global:SplashScreen.window.ShowDialog()
$Script:runspace.Close()
$Script:runspace.Dispose()
$Global:SplashScreen.Error = $Error
}) | Out-Null
#only run splash screen if enabled & testmode is disabled
If($MenuShowSplashScreen -and !$TestMode){
Start-UISplashScreen
Show-UISplashScreenProgress -Label ("Loading UI [ver {0}], please wait..." -f $MenuVersion) -Indeterminate
}
##*=============================================
##* VARIABLE DECLARATION
##*=============================================
#generate a random password
$script:RandomPassword = New-SWRandomPassword -MinPasswordLength 8 -MaxPasswordLength 12 -Count 1 -FirstChar 'abcdefghijkmnpqrstuvwxyzABCEFGHJKLMNPQRSTUVWXYZ'
#get system info
Write-Verbose "Grabbing System properties Variables..."
$DeviceInfo = Get-PlatformInfo
$primaryinterface = Get-InterfaceDetails
$ComputerName = $DeviceInfo.computerName
$SerialNumber = $DeviceInfo.SerialNumber
$Make = $DeviceInfo.platformManufacturer
$Model = $DeviceInfo.platformModel
$MacAddress = $primaryinterface.MacAddress
$IpAddress = $primaryinterface.IPAddress
$AssetTag = $DeviceInfo.assettag
$script:PasswordValue = $script:RandomPassword
#verbose & debug settings
If($VerboseMode -or ($PSBoundParameters['Verbose']) ){$Global:VerbosePreference = 'Continue';$Global:VerboseEnabled=$True}Else{$Global:VerbosePreference = 'SilentlyContinue';$Global:VerboseEnabled=$False}
If($DebugMode -or ($PSBoundParameters['Debug'] )){$Global:DebugPreference = 'Continue';$Global:DebugEnabled=$True}Else{$Global:DebugPreference = 'SilentlyContinue';$Global:DebugEnabled=$False}
Write-LogEntry ("Verbose mode is set to: {0}" -f $VerboseEnabled.ToString()) -Severity 2
Write-LogEntry ("Debug mode is set to: {0}" -f $DebugEnabled.ToString()) -Severity 2
#===========================================================================
# XAML LANGUAGE
#===========================================================================
#region CODE: Initializes XAML language for UI
#Certain characters will need to be replaced to support XML format
$XAML = (get-content $XAMLPath -ReadCount 0) -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window' -replace 'Click=".*','/>' -replace 'Demo',''
#replace background color if specified
If($BackgroundColor){$XAML = $XAML -replace 'Background="#004275"', "Background=`"$BackgroundColor`""}
#convert XAML to XML
[xml]$XAML = $XAML
$reader = New-Object System.Xml.XmlNodeReader ([xml]$XAML)
try{
Write-LogEntry "Loading XAML file: $XAMLPath" -Severity 0
$UI=[Windows.Markup.XamlReader]::Load($reader)
}
catch{
If($MenuShowSplashScreen){Close-UISplashScreen}
$ErrorMessage = $_.Exception.Message
Write-Host "Unable to load Windows.Markup.XamlReader for $AppXAMLPath. Some possible causes for this problem include:
- .NET Framework is missing
- PowerShell must be launched with PowerShell -sta
- invalid XAML code was encountered
- The error message was [$ErrorMessage]" -ForegroundColor White -BackgroundColor Red
Exit
}
# Store Form Objects In PowerShell
#===========================================================================
#take the xaml properties & make them variables
$xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "$($WPFVariable)_$($_.Name)" -Value $UI.FindName($_.Name)}
$Global:AllFormVariables = Get-Variable $WPFVariable*
If($DebugPreference){
Write-LogEntry "Displaying interactable elements from the form" -Severity 5
$global:AllFormVariables
}
#endregion
#Alias to filter function to streamline form call
New-Alias -Name WPFVar -Value Get-FormVariable -Force -ErrorAction SilentlyContinue
#identify all items in XAML that are input fields.
$InputFields = @("inputCmbSiteList","inputCmbTimeZoneList","inputCmbDomainWorkgroupName","inputTxtDomainWorkgroupName","inputCmbDomainOU")
$ButtonFields = @("Begin","Next")
#===========================================================================
# DATA: Populate menu with the Data & looks
#===========================================================================
#populate Device info in fields
(WPFVar "txtAssetTag").Text = $AssetTag
(WPFVar "txtSerialNumber").Text = $SerialNumber
(WPFVar "txtManufacturer").Text = $Make
(WPFVar "txtModel").Text = $model
(WPFVar "txtMac").Text = $MacAddress
(WPFVar "txtIP").Text = $IpAddress
#show menu version if in verbose/debug mode
If($VerboseEnabled -or $DebugEnabled){(WPFVar "Version" -Wildcard) | Set-UIFieldElement -Text ('Build Version: ' + $MenuVersion + ' (' + $MenuDate + ')')}
#disable Begin Buttons until Validation is done
(WPFVar "Begin" -Wildcard) | Set-UIFieldElement -Enable:$false -ErrorAction SilentlyContinue
#hide log images to start
(WPFVar "ImgLogo" -Wildcard) | Set-UIFieldElement -Visible:$False
#resolve logo 1 and check position
If($Logo1ImgPath -and ( ($null -ne $Logo1Position) -or ($Logo1Position -ne 'hidden' ) ) )
{
If(Resolve-Path $Logo1ImgPath -ErrorAction SilentlyContinue)
{
switch($Logo1Position){
'Left' {
(WPFVar "ImgLogoLeft" -Wildcard) | Set-UIFieldElement -Visible:$true -Source $Logo1ImgPath
}
'Right' {
(WPFVar "ImgLogoRight" -Wildcard) | Set-UIFieldElement -Visible:$true -Source $Logo1ImgPath
}
'Both' {
(WPFVar "ImgLogo" -Wildcard) | Set-UIFieldElement -Visible:$true -Source $Logo1ImgPath
}
default {
If($Logo2Position -ne 'both'){(WPFVar "ImgLogoLeft" -Wildcard) | Set-UIFieldElement -Visible:$true -Source $Logo1ImgPath}
}
}
}
}
#resolve logo 2 and check position
If($Logo2ImgPath -and ( ($null -ne $Logo2Position) -or ($Logo2Position -ne 'hidden' ) ) )
{
If(Resolve-Path $Logo2ImgPath -ErrorAction SilentlyContinue)
{
switch($Logo2Position){
'Left' {
(WPFVar "ImgLogoLeft" -Wildcard) | Set-UIFieldElement -Visible:$true -Source $Logo2ImgPath
}
'Right' {
(WPFVar "ImgLogoRight" -Wildcard) | Set-UIFieldElement -Visible:$true -Source $Logo2ImgPath
}
'Both' {
(WPFVar "ImgLogo" -Wildcard) | Set-UIFieldElement -Visible:$true -Source $Logo2ImgPath
}
default {
If($Logo1Position -ne 'both'){(WPFVar "ImgLogoRight" -Wildcard) | Set-UIFieldElement -Visible:$true -Source $Logo2ImgPath}
}
}
}
}
#replace title
(WPFVar "Tab1MainTitle").Text = (WPFVar "Tab1MainTitle").Text -replace "@Title",$MenuTitle
#hide error screen
(WPFVar "txtError").Visibility = 'Hidden'
#on load make a default password field gray to demonstrate example
(WPFVar "inputTxtPassword").Foreground = 'LightGray'
(WPFVar "inputTxtPasswordConfirm").Foreground = 'LightGray'
(WPFVar "inputTxtPassword").Password = $script:PasswordValue
(WPFVar "inputTxtPasswordConfirm").Password = $script:PasswordValue
#fill in computername example
If($NameStandardRuleExampleText){
#replace the xaml resource example with config's example
(WPFVar "lblComputerNameExample").Content = '(eg. ' + $NameStandardRuleExampleText + ')'
}
Else{
#If config has no example, use xaml reource file, but just grab the value
$NameStandardRuleExampleText = ((WPFVar 'lblComputerNameExample').Content -replace "\(eg.|\)","").Trim()
}
#Get all timezones & populate it to combo box
If($MenuShowSplashScreen){Show-UISplashScreenProgress -Label ("Populating Time Zones..." -f $MenuVersion) -Indeterminate}
$AllTimeZones = Add-UITimeZoneList -TimeZoneField (WPFVar "inputCmbTimeZoneList") -ReturnList
If($MenuEnableValidateNameRules){
#Change to first sub tab
Switch-TabItem -TabControlObject (WPFVar "subtabControl") -increment 1
#Set the fields to disable until name is validated
Get-UIFieldElement -Name $InputFields | Set-UIFieldElement -Enable:$false -ErrorAction SilentlyContinue
Get-UIFieldElement -Name $ButtonFields | Set-UIFieldElement -Enable:$false -ErrorAction SilentlyContinue
}
Else{
#hide validation section if not enabled
(WPFVar "btnTab1Validate").Visibility = 'Hidden'
(WPFVar "subtab2").Visibility = 'Hidden'
#make sure all field are enabled
Get-UIFieldElement -Name $InputFields | Set-UIFieldElement -Enable:$true -ErrorAction SilentlyContinue
Get-UIFieldElement -Name $ButtonFields | Set-UIFieldElement -Enable:$true -ErrorAction SilentlyContinue
}
#Hide if OU selection if not enabled
If(!$MenuShowDomainOUSelection){Get-UIFieldElement -Name "DomainOU" | Set-UIFieldElement -Visible:$false}
#switch domain field from combobox to textbox
If($MenuAllowCustomDomain -or $MenuLocaleDomainList.count -eq 0)
{
#hide dropdown & enable textbox
(WPFVar "inputCmbDomainWorkgroupName").Visibility = 'Hidden'
(WPFVar "inputTxtDomainWorkgroupName").Visibility = 'Visible'
#$UseDomainNameObject = (WPFVar "inputTxtDomainWorkgroupName")
}
Else
{
#hide textbox & enable dropdown
(WPFVar "inputCmbDomainWorkgroupName").Visibility = 'Visible'
(WPFVar "inputTxtDomainWorkgroupName").Visibility = 'Hidden'
#$UseDomainNameObject = (WPFVar "inputCmbDomainWorkgroupName")
#pre-populate all domain FQDN in dropdown
If($MenuShowSplashScreen){Show-UISplashScreenProgress -Label ("Populating Domains..." -f $MenuVersion) -Indeterminate}
Add-UIDomainNameList -DomainList $MenuLocaleDomainList.FQDN -DomainNameField (WPFVar "inputCmbDomainWorkgroupName") -TypeFilter $MenuFilterAccountDomainType
#Add workgroup is allowed
If($MenuAllowWorkgroupJoin){(WPFVar "inputCmbDomainWorkgroupName").Items.Add('Workgroup') | Out-Null}
}
#check if show classification section is used & display it
#this will hide the site code section
If( ($MenuShowClassificationProperty -eq 'None') -or ([string]::IsNullOrEmpty($MenuShowClassificationProperty)) ){
Get-UIFieldElement -Name "grdClassification" | Set-UIFieldElement -Visible:$false -ErrorAction SilentlyContinue
}
Else{
Get-UIFieldElement -Name "grdClassification" | Set-UIFieldElement -Visible:$true -ErrorAction SilentlyContinue
Get-UIFieldElement -Name "grdSiteCode" | Set-UIFieldElement -Visible:$false -ErrorAction SilentlyContinue
}
#check if site code section is used & display it
#this will hide the classification section
If($MenuShowSiteCode){
Get-UIFieldElement -Name "grdClassification" | Set-UIFieldElement -Visible:$false -ErrorAction SilentlyContinue
Get-UIFieldElement -Name "grdSiteCode" | Set-UIFieldElement -Visible:$true -ErrorAction SilentlyContinue
}
Else{
Get-UIFieldElement -Name "grdSiteCode" | Set-UIFieldElement -Visible:$false -ErrorAction SilentlyContinue
}
#control app section
If($MenuShowAppSelection)
{
#hide all default apps for initial set
Get-UIFieldElement -Name "tglAppInstall" | Set-UIFieldElement -Visible:$False
#Add apps selection from config
Add-AppContent -AppData $MenuAppButtonsItems
#enable the apptab
$ActiveBeginBtn = Enable-AppTab -FlipButtons -ReturnActiveBtn
}
Else{
$ActiveBeginBtn = Disable-AppTab -FlipButtons -ReturnActiveBtn
}
#Populate site list
If($MenuShowSiteListSelection -and $MenuLocaleSiteList.count -gt 0)
{
If($MenuShowSplashScreen){Show-UISplashScreenProgress -Label ("Populating Sites from list..." -f $MenuVersion) -Indeterminate}
Add-UISiteList -SiteList $MenuLocaleSiteList -SiteListField (WPFVar "inputCmbSiteList") -DisplayFormat $DisplayFormat
#be sure to show the menu
(WPFVar "SiteList" -Wildcard) | Set-UIFieldElement -Visible:$MenuShowSiteListSelection
}
Else
{
(WPFVar "SiteList" -Wildcard) | Set-UIFieldElement -Visible:$false
#move timezone up
(WPFVar "lblTimeZoneList").Margin = "160,212,0,0"
(WPFVar "inputCmbTimeZoneList").Margin = "160,243,0,0"
}
#When enabled, Network detection can only be used if there are values in the list & Site List is enabled
If($MenuEnableNetworkDetection -and ($MenuLocaleNetworkList.count -gt 0) -and $MenuShowSiteListSelection){
#detemine if value in config matches the network the device it on
Foreach($network in $MenuLocaleNetworkList){
If($network.CidrAddr -eq $primaryinterface.CidrID){
#updates the locale fields
$SelectedLocaleFields = Update-UILocaleFields -SiteList $MenuLocaleSiteList -SiteID $network.SiteId `
-UpdateSiteListObject (WPFVar "inputCmbSiteList") `
-UpdateTimeZoneObject (WPFVar "inputCmbTimeZoneList") `
-UpdateSiteCodeObject (WPFVar "txtSiteCode") `
-UpdateDomainObject (WPFVar "inputCmbDomainWorkgroupName") -ReturnProperties
}
}
}
#Generate Computer name based on config control
switch -Wildcard ($MenuGenerateNameMethod){
'ODJ*' {
If($MenuShowSplashScreen){Show-UISplashScreenProgress -Label ("Searching Offline Domain Join (ODJ) File..." -f $MenuVersion) -Indeterminate}
$ODJNetworkPath = $MenuGenerateNameSource
$DeviceODJs = Get-ChildItem $ODJNetworkPath -Filter "*.odj" -Recurse
If($Null -ne $DeviceODJs){
#build the name to look for:
#Must be named: <assettag>_<serialnumber>_<computername>.odj
$FileName = ($AssetTag + '_' + $SerialNumber + '_')
$DeviceODJ = $DeviceODJs | Where {$_.BaseName -like "$FileName*"}
If($DeviceODJ)
{
If($MenuShowSplashScreen){Show-UISplashScreenProgress -Label ("Found ODJ File, populating device details..." -f $MenuVersion) -Indeterminate}
#split file into sections to determine variables
$ODJAssetTag = ($DeviceODJ.BaseName).Split("_")[0]
$ODJSerialNumber = ($DeviceODJ.BaseName).Split("_")[1]
$ComputerName = ($DeviceODJ.BaseName).Split("_")[2]
Write-LogEntry ("Found a ODJ file that matches assest tag [{0}] and serial number [{1}]" -f $ODJAssetTag,$ODJSerialNumber) -Severity 0
#detemine if content exist in blob (could be blank file)
$ODJBlobData = Get-Content ($DeviceODJ.FullName)
If([string]::IsNullOrEmpty($ODJBlobData))
{
(WPFVar "grdDomainSection").Visibility = 'Visible'
Write-LogEntry ("ODJ file is empty, domain credentials are still required! Auto naming device [{0}] " -f $ComputerName) -Severity 2
}
Else{
(WPFVar "grdDomainSection").Visibility = 'Hidden'
(WPFVar "lblComputerNameExample").Visibility = 'Hidden'
(WPFVar "lblComputerNameQuestion").Content = "Device Name has been generated, Please validate before continuing."
Set-UIFieldElement -FieldName @("inputTxtComputerName","inputCmbSiteList") -Enable:$false
}
}
Else{
Write-LogEntry ("Unable to find a ODJ file that matches assest tag and serial number") -Severity 3
$MenuGenerateNameMethod = $null
$ComputerName = $null
(WPFVar "grdDomainSection").Visibility = 'Visible'
}
}
Else{
Write-LogEntry ("Unable to access network share [{0}] to retrieve ODJ file" -f $MenuGenerateNameSource) -Severity 3
$MenuGenerateNameMethod = $null
$ComputerName = $null
}
}
'AD' {
$ADLDAP = $MenuGenerateNameSource
#Add function to Identify all AD objects & compare with name
}
'SQL'{
$SQLConn = $MenuGenerateNameSource
#Add function to Query SQL for name (prepopulated)
}
'Locale' {
$LocalDB = $MenuGenerateNameSource
#Add function to Randomizes computer name, name can be controlled using networkdetection locale & rules
}
'WinPE' {
If($Script:tsenv)
{
$ComputerName = $tsenv.Value("OSDCOMPUTERNAME")
}Else{
$ComputerName = New-OSDComputerName
}
}
default {
#Do nothing
$ComputerName = $null
}
}
#====================================
# CHANGE EVENTS
#====================================
#Textbox placeholder remove default text when textbox is being used
(WPFVar "inputTxtComputerName").Add_GotFocus({
#if it has an example
if ((WPFVar "inputTxtComputerName").Text -eq $NameStandardRuleExampleText) {
#clear value and make it black bold ready for input
(WPFVar "inputTxtComputerName").Text = ''
(WPFVar "inputTxtComputerName").Foreground = 'Black'
(WPFVar "inputTxtComputerName").FontWeight = 'Medium'
#should be black while typing....
}
#if it does not have an example
Else{
#ensure test is black and medium
(WPFVar "inputTxtComputerName").Foreground = 'Black'
(WPFVar "inputTxtComputerName").FontWeight = 'Medium'
}
If($ComputerName){
(WPFVar "inputTxtComputerName").Text = $ComputerName
}
})
#Textbox placeholder grayed out text when textbox empty and not in being used
(WPFVar "inputTxtComputerName").Add_LostFocus({
#if text is null (after it has been clicked on which cleared by the Gotfocus event)
if ((WPFVar "inputTxtComputerName").Text -eq '') {
#add example back in light gray font
(WPFVar "inputTxtComputerName").Foreground = 'LightGray'
(WPFVar "inputTxtComputerName").FontWeight = 'Light'
(WPFVar "inputTxtComputerName").Text = $NameStandardRuleExampleText
}
})
#Textbox placeholder remove default text when textbox is being used
(WPFVar "inputTxtDomainAdminLocalAccount").Add_GotFocus({
If((WPFVar "inputTxtPassword").Password -eq $script:PasswordValue){
(WPFVar "inputTxtPassword").Password = ''
}
If((WPFVar "inputTxtPasswordConfirm").Password -eq $script:PasswordValue){
(WPFVar "inputTxtPasswordConfirm").Password = ''
}
})
#After typing in user account, make password fiels black text
(WPFVar "inputTxtPassword").Add_LostFocus({
If((WPFVar "inputTxtPassword").Password -eq $script:PasswordValue){
(WPFVar "inputTxtPassword").Password = ''
}
If((WPFVar "inputTxtPasswordConfirm").Password -eq $script:PasswordValue){
(WPFVar "inputTxtPasswordConfirm").Password = ''
}
})
#After typing in user account, make password fiels black text
(WPFVar "inputTxtPasswordConfirm").Add_LostFocus({
If((WPFVar "inputTxtPassword").Password -eq $script:PasswordValue){
(WPFVar "inputTxtPassword").Password = ''
}
If((WPFVar "inputTxtPasswordConfirm").Password -eq $script:PasswordValue){
(WPFVar "inputTxtPasswordConfirm").Password = ''
}
})
#After typing in user account, make password fiels black text
(WPFVar "inputTxtDomainAdminLocalAccount").Add_LostFocus({
(WPFVar "inputTxtPassword").Foreground = 'Black'
(WPFVar "inputTxtPasswordConfirm").Foreground = 'Black'
})
#reset computer name details
$Global:ComputerNameDetails = $null
#handle the selection change
(WPFVar "inputCmbSiteList").Add_SelectionChanged({
#update computername. Start position is null at first.
$SiteInfo = Update-ComputerNameLocale -SiteLocale (WPFVar "inputCmbSiteList").SelectedItem `
-StartPosition $Global:ComputerNameDetails.CharPosition `
-UpdateComputeName:$MenuEnableValidateNameRules -ReturnSiteInfo
#get current site list where the name matches
$SelectedLocaleFields = Update-UILocaleFields -SiteList $MenuLocaleSiteList -SiteID $SiteInfo.SiteID `
-UpdateSiteListObject (WPFVar "inputCmbSiteList") `
-UpdateTimeZoneObject (WPFVar "inputCmbTimeZoneList") `
-UpdateSiteCodeObject (WPFVar "txtSiteCode") `
-UpdateDomainObject (WPFVar "inputCmbDomainWorkgroupName") -ReturnProperties
Write-LogEntry ("Changed Locale TimeZone to: {0}" -f $SelectedLocaleFields.TimeZoneOSDName) -Severity 1
#Grab computer name details to populate character position to update the site id in the computer name ONLY if a new site is selected.
$Global:ComputerNameDetails = Get-ComputerNameLocale -ReturnDetails
})
#Grab the text value if cursor is in field
$script:FocusedComputerName = $null
$script:FirstTimeBootup = $true
(WPFVar "inputTxtComputerName").AddHandler(
[System.Windows.Controls.Primitives.TextBoxBase]::GotFocusEvent,
[System.Windows.RoutedEventHandler]{
#set a variable if there is text in field BEFORE the new name is typed
If((WPFVar "inputTxtComputerName").Text){
$script:FocusedComputerName = (WPFVar "inputTxtComputerName").Text
}
}
)
#Grab the text value when cursor leaves (AFTER Typed)
(WPFVar "inputTxtComputerName").AddHandler(
[System.Windows.Controls.Primitives.TextBoxBase]::LostFocusEvent,
[System.Windows.RoutedEventHandler]{
#because there is a example text field in the box by default, check for that
If((WPFVar "inputTxtComputerName").Text -eq (WPFVar 'lblComputerNameExample').Content){
If($MenuEnableValidateNameRules){
Invoke-UIMessage -Message "Enter a device name and validate to continue" -HighlightObject (WPFVar "inputTxtComputerName") -OutputErrorObject (WPFVar "txtError") -Type Info
Get-UIFieldElement -Name $ButtonFields | Set-UIFieldElement -Enable:$false -ErrorAction SilentlyContinue
}
}
#check if the BEFORE type value is different than the AFTER typed
ElseIf($script:FocusedComputerName -ne (WPFVar "inputTxtComputerName").Text){
#for the first time, don't display a message, but show message after all others
If($script:FirstTimeBootup){
$script:FirstTimeBootup = $false
}
Else{
If($MenuEnableValidateNameRules){
Invoke-UIMessage -Message "Detected device name change, press validate to continue" -HighlightObject (WPFVar "inputTxtComputerName") -OutputErrorObject (WPFVar "txtError") -Type Warning
Get-UIFieldElement -Name $ButtonFields | Set-UIFieldElement -Enable:$false -ErrorAction SilentlyContinue
}
}
}
}
)
#make sure domain name textbox synced with dropdown selection
#this allows for Set-OSDDomainvariables or Set-OSDWorkgroupVariables to be updated without code to support dropdown object
(WPFVar "inputCmbDomainWorkgroupName").Add_SelectionChanged({
#populate domain name for Domain account based on selection
If((WPFVar "inputCmbDomainWorkgroupName").SelectedItem -ne 'Workgroup')
{
#If OU enabled Populate Domain OU list. Move domain name field up to make room
If($MenuShowDomainOUSelection -and $MenuLocaleDomainOUList.count -gt 0)
{
(WPFVar "DomainOU" -Wildcard) | Set-UIFieldElement -Visible:$true
}
Else
{
#move Domain join down & hide Domain OU
(WPFVar "DomainOU" -Wildcard) | Set-UIFieldElement -Visible:$false
}
#change label & account description (this ensures if workgroup is selected then changed back to domain, the values change back)
(WPFVar "lblDomainCredsInstruction").Content = 'You must provide credentials with permissions to join the domain'
(WPFVar "lblDomainCredsExample").Content = '(eg. domain\first.last.adm)'
(WPFVar "lblDomainAccountWorkgroupName").Content = 'Domain Account'
#grab current value & just replace the domain value before
$CurrentUserValue = (WPFVar "inputTxtDomainAdminLocalAccount").text
$OldDomain = [regex]::Match($CurrentUserValue,'^[^\\]*').Value
If(!$OldDomain){$AddSlash = '\'}Else{$AddSlash = ''}
#grab Domain Name from config list based on FQDN
If($MenuFilterAccountDomainType){
$SelectedClassid = ($MenuLocaleDomainList | Where FQDN -eq (WPFVar "inputCmbDomainWorkgroupName").SelectedItem).ClassId
#if multiple types exist for same classification, be sure to just select one
$SelectFirstDomain = ($MenuLocaleDomainList | Where {($_.ClassId -eq $SelectedClassid) -and ($_.Type -eq $MenuFilterAccountDomainType)}).Name | Select -First 1
$SelectedDomainName = $SelectFirstDomain + $AddSlash
}
Else{