Public/New-OSBuildTask.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
<#
.SYNOPSIS
Creates a JSON Task for use with New-OSBuild

.DESCRIPTION
Creates a JSON Task for use with New-OSBuild

.LINK
https://www.osdeploy.com/osbuilder/docs/functions/osbuild/new-osbuildtask

.PARAMETER TaskName
Name of the Task to create

.PARAMETER CustomName
Custom Name of the OSBuild

.PARAMETER DisableWindowsOptionalFeature
Disables an Enabled Windows Optional Feature

.PARAMETER EnableNetFX3
Enables NetFX3 in the OSBuild

.PARAMETER EnableWindowsOptionalFeature
Enables a Disabled Windows Optional Feature

.PARAMETER RemoveAppxProvisionedPackage
Displays a GridView to select Appx Provisioned Packages to Remove

.PARAMETER RemoveWindowsPackage
Displays a GridView to select Windows Packages to Remove

.PARAMETER RemoveWindowsCapability
Displays a GridView to select Windows Capabilities to Remove
#>

function New-OSBuildTask {
    [CmdletBinding(DefaultParameterSetName='Basic')]
    PARAM (
        [Parameter(Mandatory)]
        [string]$TaskName,
        [string]$CustomName,
        [switch]$EnableNetFX3,
        [switch]$RemoveAppxProvisionedPackage,
        [switch]$RemoveWindowsPackage,
        [switch]$RemoveWindowsCapability,
        [switch]$DisableWindowsOptionalFeature,
        [switch]$EnableWindowsOptionalFeature,
        [switch]$WinPEAutoExtraFiles,
        #[ValidateSet('ar-SA','bg-BG','zh-CN','zh-TW','hr-HR','cs-CZ','da-DK','nl-NL','en-US','en-GB','et-EE','fi-FI','fr-CA','fr-FR','de-DE','el-GR','he-IL','hu-HU','it-IT','ja-JP','ko-KR','lv-LV','lt-LT','nb-NO','pl-PL','pt-BR','pt-PT','ro-RO','ru-RU','sr-Latn-RS','sk-SK','sl-SI','es-MX','es-ES','sv-SE','th-TH','tr-TR','uk-UA')]
        #[ValidateSet('af-ZA','am-ET','as-IN','az-Latn-AZ','be-BY','bn-BD','bn-IN','bs-Latn-BA','ca-ES','ca-ES-valencia','chr-CHER-US','cy-GB','eu-ES','fa-IR','fil-PH','ga-IE','gd-GB','gl-ES','gu-IN','ha-Latn-NG','hi-IN','hy-AM','id-ID','ig-NG','is-IS','ka-GE','kk-KZ','km-KH','kn-IN','kok-IN','ku-ARAB-IQ','ky-KG','lb-LU','lo-LA','mi-NZ','mk-MK','ml-IN','mn-MN','mr-IN','ms-MY','mt-MT','ne-NP','nn-NO','nso-ZA','or-IN','pa-Arab-PK','pa-IN','prs-AF','quc-Latn-GT','quz-PE','rw-RW','sd-Arab-PK','si-LK','sq-AL','sr-Cyrl-BA','sr-Cyrl-RS','sw-KE','ta-IN','te-IN','tg-Cyrl-TJ','ti-ET','tk-TM','tn-ZA','tt-RU','ug-CN','ur-PK','uz-Latn-UZ','vi-VN','wo-SN','xh-ZA','yo-NG','zu-ZA')]
        [Parameter(ParameterSetName='Language')]
        [ValidateSet('ar-SA','bg-BG','zh-CN','zh-TW','hr-HR','cs-CZ','da-DK','nl-NL','en-US','en-GB','et-EE','fi-FI','fr-CA','fr-FR','de-DE','el-GR','he-IL','hu-HU','it-IT','ja-JP','ko-KR','lv-LV','lt-LT','nb-NO','pl-PL','pt-BR','pt-PT','ro-RO','ru-RU','sr-Latn-RS','sk-SK','sl-SI','es-MX','es-ES','sv-SE','th-TH','tr-TR','uk-UA','af-ZA','am-ET','as-IN','az-Latn-AZ','be-BY','bn-BD','bn-IN','bs-Latn-BA','ca-ES','ca-ES-valencia','chr-CHER-US','cy-GB','eu-ES','fa-IR','fil-PH','ga-IE','gd-GB','gl-ES','gu-IN','ha-Latn-NG','hi-IN','hy-AM','id-ID','ig-NG','is-IS','ka-GE','kk-KZ','km-KH','kn-IN','kok-IN','ku-ARAB-IQ','ky-KG','lb-LU','lo-LA','mi-NZ','mk-MK','ml-IN','mn-MN','mr-IN','ms-MY','mt-MT','ne-NP','nn-NO','nso-ZA','or-IN','pa-Arab-PK','pa-IN','prs-AF','quc-Latn-GT','quz-PE','rw-RW','sd-Arab-PK','si-LK','sq-AL','sr-Cyrl-BA','sr-Cyrl-RS','sw-KE','ta-IN','te-IN','tg-Cyrl-TJ','ti-ET','tk-TM','tn-ZA','tt-RU','ug-CN','ur-PK','uz-Latn-UZ','vi-VN','wo-SN','xh-ZA','yo-NG','zu-ZA')]
        [string]$SetAllIntl,
        [Parameter(ParameterSetName='Language')]
        [string]$SetInputLocale,
        [Parameter(ParameterSetName='Language')]
        [ValidateSet('ar-SA','bg-BG','zh-CN','zh-TW','hr-HR','cs-CZ','da-DK','nl-NL','en-US','en-GB','et-EE','fi-FI','fr-CA','fr-FR','de-DE','el-GR','he-IL','hu-HU','it-IT','ja-JP','ko-KR','lv-LV','lt-LT','nb-NO','pl-PL','pt-BR','pt-PT','ro-RO','ru-RU','sr-Latn-RS','sk-SK','sl-SI','es-MX','es-ES','sv-SE','th-TH','tr-TR','uk-UA','af-ZA','am-ET','as-IN','az-Latn-AZ','be-BY','bn-BD','bn-IN','bs-Latn-BA','ca-ES','ca-ES-valencia','chr-CHER-US','cy-GB','eu-ES','fa-IR','fil-PH','ga-IE','gd-GB','gl-ES','gu-IN','ha-Latn-NG','hi-IN','hy-AM','id-ID','ig-NG','is-IS','ka-GE','kk-KZ','km-KH','kn-IN','kok-IN','ku-ARAB-IQ','ky-KG','lb-LU','lo-LA','mi-NZ','mk-MK','ml-IN','mn-MN','mr-IN','ms-MY','mt-MT','ne-NP','nn-NO','nso-ZA','or-IN','pa-Arab-PK','pa-IN','prs-AF','quc-Latn-GT','quz-PE','rw-RW','sd-Arab-PK','si-LK','sq-AL','sr-Cyrl-BA','sr-Cyrl-RS','sw-KE','ta-IN','te-IN','tg-Cyrl-TJ','ti-ET','tk-TM','tn-ZA','tt-RU','ug-CN','ur-PK','uz-Latn-UZ','vi-VN','wo-SN','xh-ZA','yo-NG','zu-ZA')]
        [string]$SetSKUIntlDefaults,
        [Parameter(ParameterSetName='Language')]
        [ValidateSet('ar-SA','bg-BG','zh-CN','zh-TW','hr-HR','cs-CZ','da-DK','nl-NL','en-US','en-GB','et-EE','fi-FI','fr-CA','fr-FR','de-DE','el-GR','he-IL','hu-HU','it-IT','ja-JP','ko-KR','lv-LV','lt-LT','nb-NO','pl-PL','pt-BR','pt-PT','ro-RO','ru-RU','sr-Latn-RS','sk-SK','sl-SI','es-MX','es-ES','sv-SE','th-TH','tr-TR','uk-UA','af-ZA','am-ET','as-IN','az-Latn-AZ','be-BY','bn-BD','bn-IN','bs-Latn-BA','ca-ES','ca-ES-valencia','chr-CHER-US','cy-GB','eu-ES','fa-IR','fil-PH','ga-IE','gd-GB','gl-ES','gu-IN','ha-Latn-NG','hi-IN','hy-AM','id-ID','ig-NG','is-IS','ka-GE','kk-KZ','km-KH','kn-IN','kok-IN','ku-ARAB-IQ','ky-KG','lb-LU','lo-LA','mi-NZ','mk-MK','ml-IN','mn-MN','mr-IN','ms-MY','mt-MT','ne-NP','nn-NO','nso-ZA','or-IN','pa-Arab-PK','pa-IN','prs-AF','quc-Latn-GT','quz-PE','rw-RW','sd-Arab-PK','si-LK','sq-AL','sr-Cyrl-BA','sr-Cyrl-RS','sw-KE','ta-IN','te-IN','tg-Cyrl-TJ','ti-ET','tk-TM','tn-ZA','tt-RU','ug-CN','ur-PK','uz-Latn-UZ','vi-VN','wo-SN','xh-ZA','yo-NG','zu-ZA')]
        [string]$SetSetupUILang,
        [Parameter(ParameterSetName='Language')]
        [string]$SetSysLocale,
        [Parameter(ParameterSetName='Language')]
        [ValidateSet('ar-SA','bg-BG','zh-CN','zh-TW','hr-HR','cs-CZ','da-DK','nl-NL','en-US','en-GB','et-EE','fi-FI','fr-CA','fr-FR','de-DE','el-GR','he-IL','hu-HU','it-IT','ja-JP','ko-KR','lv-LV','lt-LT','nb-NO','pl-PL','pt-BR','pt-PT','ro-RO','ru-RU','sr-Latn-RS','sk-SK','sl-SI','es-MX','es-ES','sv-SE','th-TH','tr-TR','uk-UA','af-ZA','am-ET','as-IN','az-Latn-AZ','be-BY','bn-BD','bn-IN','bs-Latn-BA','ca-ES','ca-ES-valencia','chr-CHER-US','cy-GB','eu-ES','fa-IR','fil-PH','ga-IE','gd-GB','gl-ES','gu-IN','ha-Latn-NG','hi-IN','hy-AM','id-ID','ig-NG','is-IS','ka-GE','kk-KZ','km-KH','kn-IN','kok-IN','ku-ARAB-IQ','ky-KG','lb-LU','lo-LA','mi-NZ','mk-MK','ml-IN','mn-MN','mr-IN','ms-MY','mt-MT','ne-NP','nn-NO','nso-ZA','or-IN','pa-Arab-PK','pa-IN','prs-AF','quc-Latn-GT','quz-PE','rw-RW','sd-Arab-PK','si-LK','sq-AL','sr-Cyrl-BA','sr-Cyrl-RS','sw-KE','ta-IN','te-IN','tg-Cyrl-TJ','ti-ET','tk-TM','tn-ZA','tt-RU','ug-CN','ur-PK','uz-Latn-UZ','vi-VN','wo-SN','xh-ZA','yo-NG','zu-ZA')]
        [string]$SetUILang,
        [Parameter(ParameterSetName='Language')]
        [ValidateSet('ar-SA','bg-BG','zh-CN','zh-TW','hr-HR','cs-CZ','da-DK','nl-NL','en-US','en-GB','et-EE','fi-FI','fr-CA','fr-FR','de-DE','el-GR','he-IL','hu-HU','it-IT','ja-JP','ko-KR','lv-LV','lt-LT','nb-NO','pl-PL','pt-BR','pt-PT','ro-RO','ru-RU','sr-Latn-RS','sk-SK','sl-SI','es-MX','es-ES','sv-SE','th-TH','tr-TR','uk-UA','af-ZA','am-ET','as-IN','az-Latn-AZ','be-BY','bn-BD','bn-IN','bs-Latn-BA','ca-ES','ca-ES-valencia','chr-CHER-US','cy-GB','eu-ES','fa-IR','fil-PH','ga-IE','gd-GB','gl-ES','gu-IN','ha-Latn-NG','hi-IN','hy-AM','id-ID','ig-NG','is-IS','ka-GE','kk-KZ','km-KH','kn-IN','kok-IN','ku-ARAB-IQ','ky-KG','lb-LU','lo-LA','mi-NZ','mk-MK','ml-IN','mn-MN','mr-IN','ms-MY','mt-MT','ne-NP','nn-NO','nso-ZA','or-IN','pa-Arab-PK','pa-IN','prs-AF','quc-Latn-GT','quz-PE','rw-RW','sd-Arab-PK','si-LK','sq-AL','sr-Cyrl-BA','sr-Cyrl-RS','sw-KE','ta-IN','te-IN','tg-Cyrl-TJ','ti-ET','tk-TM','tn-ZA','tt-RU','ug-CN','ur-PK','uz-Latn-UZ','vi-VN','wo-SN','xh-ZA','yo-NG','zu-ZA')]
        [string]$SetUILangFallback,
        [Parameter(ParameterSetName='Language')]
        [string]$SetUserLocale

    )
    BEGIN {
        #Write-Host '========================================================================================' -ForegroundColor DarkGray
        #Write-Host "$($MyInvocation.MyCommand.Name) BEGIN" -ForegroundColor Green

        #===================================================================================================
        Write-Verbose '19.1.1 Initialize OSBuilder'
        #===================================================================================================
        Get-OSBuilder -CreatePaths -HideDetails
    }
    
    PROCESS {
        Write-Host '========================================================================================' -ForegroundColor DarkGray
        Write-Host "$($MyInvocation.MyCommand.Name) PROCESS" -ForegroundColor Green
        
        #===================================================================================================
        Write-Verbose '19.1.1 Information'
        #===================================================================================================
        $TaskName = "$TaskName"
        $TaskPath = "$OSBuilderTasks\OSBuild $TaskName.json"
        
        Write-Host '========================================================================================' -ForegroundColor DarkGray
        Write-Host "New-OSBuild Task Information" -ForegroundColor Green
        Write-Host "-Task Name: $TaskName"
        Write-Host "-Task Path: $TaskPath"
        Write-Host "-Custom Name: $CustomName"
        Write-Host "-DotNet 3.5: $EnableNetFX3"
        Write-Host "-SetAllIntl: $SetAllIntl"
        Write-Host "-SetInputLocale: $SetInputLocale"
        Write-Host "-SetSKUIntlDefaults: $SetSKUIntlDefaults"
        Write-Host "-SetSetupUILang: $SetSetupUILang"
        Write-Host "-SetSysLocale: $SetSysLocale"
        Write-Host "-SetUILang: $SetUILang"
        Write-Host "-SetUILangFallback: $SetUILangFallback"
        Write-Host "-SetUserLocale: $SetUserLocale"
        Write-Host "-WinPEAutoExtraFiles: $WinPEAutoExtraFiles"

        #===================================================================================================
        Write-Verbose '19.1.1 Validate Task'
        #===================================================================================================
        if (Test-Path $TaskPath) {
            Write-Host '========================================================================================' -ForegroundColor DarkGray
            Write-Warning "Task already exists at $TaskPath"
            Write-Warning "Content will be overwritten!"
        }

        #===================================================================================================
        Write-Verbose '19.1.11 Get-OSMedia'
        #===================================================================================================
        $OSMedia = @()
        $OSMedia = Get-OSMedia | Where-Object {$_.MajorVersion -eq 10}
        #$OSMedia = Get-OSMedia

        if ($TaskName -like "*x64*") {$OSMedia = $OSMedia | Where-Object {$_.Arch -eq 'x64'}}
        if ($TaskName -like "*x86*") {$OSMedia = $OSMedia | Where-Object {$_.Arch -eq 'x86'}}
        if ($TaskName -like "*1511*") {$OSMedia = $OSMedia | Where-Object {$_.ReleaseId -eq '1511'}}
        if ($TaskName -like "*1607*") {$OSMedia = $OSMedia | Where-Object {$_.ReleaseId -eq '1607'}}
        if ($TaskName -like "*1703*") {$OSMedia = $OSMedia | Where-Object {$_.ReleaseId -eq '1703'}}
        if ($TaskName -like "*1709*") {$OSMedia = $OSMedia | Where-Object {$_.ReleaseId -eq '1709'}}
        if ($TaskName -like "*1803*") {$OSMedia = $OSMedia | Where-Object {$_.ReleaseId -eq '1803'}}
        if ($TaskName -like "*1809*") {$OSMedia = $OSMedia | Where-Object {$_.ReleaseId -eq '1809'}}

        $OSMedia = $OSMedia | Out-GridView -OutputMode Single -Title "Select a Source OSMedia to use for this Task (Cancel to Exit)"
        if ($null -eq $OSMedia) {
            Write-Warning "Source OSMedia was not selected . . . Exiting!"
            Return
        }

        #===================================================================================================
        Write-Verbose '19.1.7 Get Windows Image Information'
        #===================================================================================================
        $WindowsImage = Get-WindowsImage -ImagePath "$($OSMedia.FullName)\OS\sources\install.wim" -Index 1 | Select-Object -Property *

        #===================================================================================================
        Write-Verbose '19.1.7 Source OSMedia Windows Image Information'
        #===================================================================================================
        Write-Host '========================================================================================' -ForegroundColor DarkGray
        Write-Host "Source OSMedia Windows Image Information" -ForegroundColor Green
        Write-Host "-OSMedia Chain: $($OSMedia.OSMFamily)"
        Write-Host "-OSMedia Guid: $($OSMedia.OSMGuid)"
        Write-Host "-OSMedia Name: $($OSMedia.Name)"
        Write-Host "-OSMedia FullName: $($OSMedia.FullName)"
        Write-Host "-Image File: $($OSMedia.FullName)\OS\sources\install.wim"
        Write-Host "-Image Index: 1"
        Write-Host "-Image Name: $($OSMedia.ImageName)"
        Write-Host "-Architecture: $($OSMedia.Arch)"
        Write-Host "-ReleaseId: $($OSMedia.ReleaseId)"
        Write-Host "-UBR: $($OSMedia.UBR)"
        Write-Host "-Edition: $($OSMedia.EditionId)"
        Write-Host "-InstallationType: $($OSMedia.InstallationType)"
        Write-Host "-Languages: $($WindowsImage.Languages)"
        Write-Host "-Version: $($WindowsImage.Version)"
        Write-Host "-Major Version: $($OSMedia.MajorVersion)"
        Write-Host "-Minor Version: $($WindowsImage.MinorVersion)"
        Write-Host "-Build: $($OSMedia.Build)"
        Write-Host "-SPBuild: $($WindowsImage.SPBuild)"
        Write-Host "-SPLevel: $($WindowsImage.SPLevel)"
        Write-Host "-Bootable: $($WindowsImage.ImageBootable)"
        Write-Host "-WimBoot: $($WindowsImage.WIMBoot)"
        Write-Host "-Created Time: $($OSMedia.CreatedTime)"
        Write-Host "-Modified Time: $($OSMedia.ModifiedTime)"
        
        #===================================================================================================
        Write-Verbose '19.1.1 Validate Registry CurrentVersion.xml'
        #===================================================================================================
        if ($null -eq $($OSMedia.ReleaseId)) {
            if (Test-Path "$($OSMedia.FullName)\info\xml\CurrentVersion.xml") {
                $RegCurrentVersion = Import-Clixml -Path "$($OSMedia.FullName)\info\xml\CurrentVersion.xml"
                $OSMedia.ReleaseId = $($RegCurrentVersion.ReleaseId)
                if ($($OSMedia.ReleaseId) -gt 1809) {
                    Write-Warning "OSBuilder does not currently support this version of Windows ... Check for an updated version"
                }
            }
        }

        #===================================================================================================
        Write-Verbose '19.1.1 Set OSMedia.ReleaseId'
        #===================================================================================================
        if ($null -eq $($OSMedia.ReleaseId)) {
            if ($($OSMedia.Build) -eq 7601) {$OSMedia.ReleaseId = 7601}
            if ($($OSMedia.Build) -eq 10240) {$OSMedia.ReleaseId = 1507}
            if ($($OSMedia.Build) -eq 14393) {$OSMedia.ReleaseId = 1607}
            if ($($OSMedia.Build) -eq 15063) {$OSMedia.ReleaseId = 1703}
            if ($($OSMedia.Build) -eq 16299) {$OSMedia.ReleaseId = 1709}
            if ($($OSMedia.Build) -eq 17134) {$OSMedia.ReleaseId = 1803}
            if ($($OSMedia.Build) -eq 17763) {$OSMedia.ReleaseId = 1809}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Remove-AppxProvisionedPackage'
        #===================================================================================================
        if ($RemoveAppxProvisionedPackage.IsPresent) {
            if ($($OSMedia.InstallationType) -eq 'Client') {
                $GetAppxProvisionedPackage = @()
                if (Test-Path "$($OSMedia.FullName)\info\json\Get-AppxProvisionedPackage.json") {
                    $GetAppxProvisionedPackage = Get-Content -Path "$($OSMedia.FullName)\info\json\Get-AppxProvisionedPackage.json"
                    $GetAppxProvisionedPackage = $GetAppxProvisionedPackage | ConvertFrom-Json
                    $GetAppxProvisionedPackage = $GetAppxProvisionedPackage | Select-Object -Property DisplayName, PackageName
                    $GetAppxProvisionedPackage = $GetAppxProvisionedPackage | Out-GridView -Title "Install.wim Remove-AppxProvisionedPackage: Select Packages to REMOVE and press OK (Esc or Cancel to Skip)" -PassThru
                }
                if ($null -eq $GetAppxProvisionedPackage) {Write-Warning "Install.wim Remove-AppxProvisionedPackage: Skipping"}
            } else {Write-Warning "Install.wim Remove-AppxProvisionedPackage: Unsupported"}
        } else {Write-Warning "Install.wim Remove-AppxProvisionedPackage: Disabled"}

        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Remove-WindowsPackage'
        #===================================================================================================
        if ($RemoveWindowsPackage.IsPresent) {
            $GetWindowsPackage = @()
            if (Test-Path "$($OSMedia.FullName)\info\json\Get-WindowsPackage.json") {
                $GetWindowsPackage = Get-Content -Path "$($OSMedia.FullName)\info\json\Get-WindowsPackage.json"
                $GetWindowsPackage = $GetWindowsPackage | ConvertFrom-Json
                $GetWindowsPackage = $GetWindowsPackage | Select-Object -Property PackageName
                $GetWindowsPackage = $GetWindowsPackage | Out-GridView -Title "Install.wim Remove-WindowsPackage: Select Packages to REMOVE and press OK (Esc or Cancel to Skip)" -PassThru
            }
            if ($null -eq $GetWindowsPackage) {Write-Warning "Install.wim Remove-WindowsPackage: Skipping"}
        } else {Write-Warning "Install.wim Remove-WindowsPackage: Disabled"}

        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Remove-WindowsCapability'
        #===================================================================================================
        if ($RemoveWindowsCapability.IsPresent) {
            $GetWindowsCapability = @()
            if (Test-Path "$($OSMedia.FullName)\info\json\Get-WindowsCapability.json") {
                $GetWindowsCapability = Get-Content -Path "$($OSMedia.FullName)\info\json\Get-WindowsCapability.json"
                $GetWindowsCapability = $GetWindowsCapability | ConvertFrom-Json
                $GetWindowsCapability = $GetWindowsCapability | Select-Object -Property Name, State
                $GetWindowsCapability = $GetWindowsCapability | Out-GridView -Title "Install.wim Remove-WindowsCapability: Select Windows InBox Capability to REMOVE and press OK (Esc or Cancel to Skip)" -PassThru
            }
            if ($null -eq $GetWindowsCapability) {Write-Warning "Install.wim Remove-WindowsCapability: Skipping"}
        } else {Write-Warning "Install.wim Remove-WindowsCapability: Disabled"}

        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim WindowsOptionalFeature'
        #===================================================================================================
        $GetWindowsOptionalFeature = @()
        if (Test-Path "$($OSMedia.FullName)\info\json\Get-WindowsOptionalFeature.json") {
            $GetWindowsOptionalFeature = Get-Content -Path "$($OSMedia.FullName)\info\json\Get-WindowsOptionalFeature.json"
            $GetWindowsOptionalFeature = $GetWindowsOptionalFeature | ConvertFrom-Json
        }

        #===================================================================================================
        Write-Verbose '19.1.14 Install.wim Disable-WindowsOptionalFeature'
        #===================================================================================================
        if ($DisableWindowsOptionalFeature.IsPresent) {
            $DisableWinOptionalFeature = @()
            $DisableWinOptionalFeature = $GetWindowsOptionalFeature | Select-Object -Property FeatureName, State | Sort-Object -Property FeatureName | Where-Object {$_.State -eq 2 -or $_.State -eq 3}
            $DisableWinOptionalFeature = $DisableWinOptionalFeature | Select-Object -Property FeatureName
            $DisableWinOptionalFeature = $DisableWinOptionalFeature | Out-GridView -PassThru -Title "Install.wim Disable-WindowsOptionalFeature: Select Windows Optional Features to DISABLE and press OK (Esc or Cancel to Skip)"
            if ($null -eq $DisableWinOptionalFeature) {Write-Warning "Install.wim Disable-WindowsOptionalFeature: Skipping"}
        } else {Write-Warning "Install.wim Disable-WindowsOptionalFeature: Disabled"}

        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Enable-WindowsOptionalFeature'
        #===================================================================================================
        if ($EnableWindowsOptionalFeature.IsPresent) {
            $EnableWinOptionalFeature = @()
            $EnableWinOptionalFeature = $GetWindowsOptionalFeature | Select-Object -Property FeatureName, State | Sort-Object -Property FeatureName | Where-Object {$_.State -eq 0}
            $EnableWinOptionalFeature = $EnableWinOptionalFeature | Select-Object -Property FeatureName
            $EnableWinOptionalFeature = $EnableWinOptionalFeature | Out-GridView -PassThru -Title "Install.wim Enable-WindowsOptionalFeature: Select Windows Optional Features to ENABLE and press OK (Esc or Cancel to Skip)"
            if ($null -eq $EnableWinOptionalFeature) {Write-Warning "Install.wim Enable-WindowsOptionalFeature: Skipping"}
        } else {Write-Warning "Install.wim Enable-WindowsOptionalFeature: Disabled"}

        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim IsoExtract Content'
        #===================================================================================================
        $IsoExtractContent = @()
        if ($OSMedia.MajorVersion -eq 10) {
            $IsoExtractContent = Get-ChildItem -Path "$OSBuilderContent\IsoExtract" *.cab -Recurse | Select-Object -Property Name, FullName
            foreach ($IsoExtractPackage in $IsoExtractContent) {$IsoExtractPackage.FullName = $($IsoExtractPackage.FullName).replace("$OSBuilderContent\",'')}
        }

        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim IsoExtract Features On Demand'
        #===================================================================================================
        $IsoExtractFeaturesOnDemand =@()
        if ($OSMedia.MajorVersion -eq 10) {
            $IsoExtractFeaturesOnDemand = $IsoExtractContent
            foreach ($Pack in $IsoExtractFeaturesOnDemand) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
            $IsoExtractFeaturesOnDemand = $IsoExtractFeaturesOnDemand | Where-Object {$_.FullName -notlike "*Windows Preinstallation Environment*"}
            $IsoExtractFeaturesOnDemand = $IsoExtractFeaturesOnDemand | Where-Object {$_.Name -notlike "*lp.cab"}
            $IsoExtractFeaturesOnDemand = $IsoExtractFeaturesOnDemand | Where-Object {$_.Name -notlike "*Language-Pack*"}
            $IsoExtractFeaturesOnDemand = $IsoExtractFeaturesOnDemand | Where-Object {$_.Name -notlike "*Language-Interface-Pack*"}
            $IsoExtractFeaturesOnDemand = $IsoExtractFeaturesOnDemand | Where-Object {$_.Name -notlike "*LanguageFeatures*"}
            if ($($OSMedia.Arch) -eq 'x64') {$IsoExtractFeaturesOnDemand = $IsoExtractFeaturesOnDemand | Where-Object {$_.Name -notlike "*x86*"}}
            if ($($OSMedia.Arch) -eq 'x64') {$IsoExtractFeaturesOnDemand = $IsoExtractFeaturesOnDemand | Where-Object {$_.FullName -notlike "*W32*"}}
            if ($($OSMedia.Arch) -eq 'x86') {$IsoExtractFeaturesOnDemand = $IsoExtractFeaturesOnDemand | Where-Object {$_.Name -notlike "*x64*"}}
            if ($($OSMedia.Arch) -eq 'x86') {$IsoExtractFeaturesOnDemand = $IsoExtractFeaturesOnDemand | Where-Object {$_.Name -notlike "*amd64*"}}
            if ($($OSMedia.Arch) -eq 'x86') {$IsoExtractFeaturesOnDemand = $IsoExtractFeaturesOnDemand | Where-Object {$_.FullName -notlike "*64Bit*"}}
            if ($($OSMedia.ReleaseId)) {$IsoExtractFeaturesOnDemand = $IsoExtractFeaturesOnDemand | Where-Object {$_.FullName -like "*$($OSMedia.ReleaseId)*"}}
        }

        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Updates Features on Demand'
        #===================================================================================================
        $UpdatesFeaturesOnDemand = @()
        if ($OSMedia.MajorVersion -eq 10) {
            $UpdatesFeaturesOnDemand = Get-ChildItem -Path "$OSBuilderContent\Updates\FeatureOnDemand" *.cab -Recurse | Select-Object -Property Name, FullName
            $UpdatesFeaturesOnDemand = $UpdatesFeaturesOnDemand | Where-Object {$_.FullName -like "*$($OSMedia.Arch)*"}
            if ($($OSMedia.ReleaseId)) {$UpdatesFeaturesOnDemand = $UpdatesFeaturesOnDemand | Where-Object {$_.FullName -like "*$($OSMedia.ReleaseId)*"}}
        }

        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Features On Demand'
        #===================================================================================================
        $SelectedFeaturesOnDemand = @()
        if ($OSMedia.MajorVersion -eq 10) {
            $SelectedFeaturesOnDemand = $IsoExtractFeaturesOnDemand + $UpdatesFeaturesOnDemand
            if ($null -eq $SelectedFeaturesOnDemand) {Write-Warning "Install.wim Features On Demand: Not Found"}
            else {
                $SelectedFeaturesOnDemand = $SelectedFeaturesOnDemand | Sort-Object -Property FullName | Out-GridView -Title "Install.wim Features On Demand: Select Packages to apply and press OK (Esc or Cancel to Skip)" -PassThru
                if ($null -eq $SelectedFeaturesOnDemand) {Write-Warning "Install.wim Features On Demand: Skipping"}
            }
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim IsoExtract Language Packs'
        #===================================================================================================
        $IsoExtractLanguagePacks = @()
        if ($OSMedia.MajorVersion -eq 10) {
            $IsoExtractLanguagePacks = $IsoExtractContent | Where-Object {$_.Name -eq 'lp.cab' -or $_.Name -like "*Language-Pack*"}
            $IsoExtractLanguagePacks = $IsoExtractLanguagePacks | Where-Object {$_.FullName -notlike "*Windows Preinstallation Environment*"}
            $IsoExtractLanguagePacks = $IsoExtractLanguagePacks | Where-Object {$_.Name -notlike "*arm64*"}
            $IsoExtractLanguagePacks = $IsoExtractLanguagePacks | Where-Object {$_.Name -notlike "*Server*"}
            $IsoExtractLanguagePacks = $IsoExtractLanguagePacks | Where-Object {$_.FullName -like "*\$($OSMedia.Arch)\*"}
            if ($($OSMedia.ReleaseId)) {$IsoExtractLanguagePacks = $IsoExtractLanguagePacks | Where-Object {$_.FullName -like "*$($OSMedia.ReleaseId)*"}}
        }

        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Updates Language Packs'
        #===================================================================================================
        $UpdatesLanguagePacks = @()
        if ($OSMedia.MajorVersion -eq 10) {
            $UpdatesLanguagePacks = Get-ChildItem -Path "$OSBuilderContent\Updates\LanguagePack" *.cab -Recurse | Select-Object -Property Name, FullName
            $UpdatesLanguagePacks = $UpdatesLanguagePacks | Where-Object {$_.FullName -like "*$($OSMedia.Arch)*"}
            if ($($OSMedia.ReleaseId)) {$UpdatesLanguagePacks = $UpdatesLanguagePacks | Where-Object {$_.FullName -like "*$($OSMedia.ReleaseId)*"}}
        }

        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Legacy Language Packs'
        #===================================================================================================
        $LegacyLanguagePacks = @()
        if ($OSMedia.MajorVersion -eq 10) {
            if (Test-Path "$OSBuilderContent\LanguagePacks") {
                $LegacyLanguagePacks = Get-ChildItem -Path "$OSBuilderContent\LanguagePacks" *.cab -Recurse | Select-Object -Property Name, FullName
                $LegacyLanguagePacks = $LegacyLanguagePacks | Where-Object {$_.FullName -like "*$($OSMedia.Arch)*"}
                if ($($OSMedia.ReleaseId)) {$LegacyLanguagePacks = $LegacyLanguagePacks | Where-Object {$_.FullName -like "*$($OSMedia.ReleaseId)*"}}
            }
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Language Packs'
        #===================================================================================================
        $SelectedLanguagePacks = @()
        if ($OSMedia.MajorVersion -eq 10) {
            $SelectedLanguagePacks = $IsoExtractLanguagePacks + $UpdatesLanguagePacks + $LegacyLanguagePacks
            foreach ($Package in $SelectedLanguagePacks) {$Package.FullName = $($Package.FullName).replace("$OSBuilderContent\",'')}
            if ($null -eq $SelectedLanguagePacks) {Write-Warning "Install.wim Language Packs: Not Found"}
            else {
                $SelectedLanguagePacks = $SelectedLanguagePacks | Sort-Object -Property FullName | Out-GridView -Title "Install.wim Language Packs: Select Packages to apply and press OK (Esc or Cancel to Skip)" -PassThru
                if ($null -eq $SelectedLanguagePacks) {Write-Warning "Install.wim Language Packs: Skipping"}
            }
        }

        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim IsoExtract Language Interface Packs'
        #===================================================================================================
        $IsoExtractLanguageInterfacePacks = @()
        $IsoExtractLanguageInterfacePacks = $IsoExtractContent | Where-Object {$_.Name -like "*Language-Interface-Pack*"}
        $IsoExtractLanguageInterfacePacks = $IsoExtractLanguageInterfacePacks | Where-Object {$_.Name -notlike "*arm64*"}
        $IsoExtractLanguageInterfacePacks = $IsoExtractLanguageInterfacePacks | Where-Object {$_.Name -like "*$($OSMedia.Arch)*"}
        if ($($OSMedia.ReleaseId)) {$IsoExtractLanguageInterfacePacks = $IsoExtractLanguageInterfacePacks | Where-Object {$_.FullName -like "*$($OSMedia.ReleaseId)*"}}
        
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Updates Language Interface Packs'
        #===================================================================================================
        $UpdatesLanguageInterfacePacks = @()
        $UpdatesLanguageInterfacePacks = Get-ChildItem -Path "$OSBuilderContent\Updates\LanguageInterfacePack" *.cab -Recurse | Select-Object -Property Name, FullName
        $UpdatesLanguageInterfacePacks = $UpdatesLanguageInterfacePacks | Where-Object {$_.FullName -like "*$($OSMedia.Arch)*"}
        if ($($OSMedia.ReleaseId)) {$UpdatesLanguageInterfacePacks = $UpdatesLanguageInterfacePacks | Where-Object {$_.FullName -like "*$($OSMedia.ReleaseId)*"}}
       
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Select Language Interface Packs'
        #===================================================================================================
        $SelectedLanguageInterfacePacks = @()
        if ($OSMedia.MajorVersion -eq 10) {
            $SelectedLanguageInterfacePacks = $IsoExtractLanguageInterfacePacks + $UpdatesLanguageInterfacePacks
            foreach ($Package in $SelectedLanguageInterfacePacks) {$Package.FullName = $($Package.FullName).replace("$OSBuilderContent\",'')}
            if ($null -eq $SelectedLanguageInterfacePacks) {Write-Warning "Install.wim Language Interface Packs: Not Found"}
            else {
                $SelectedLanguageInterfacePacks = $SelectedLanguageInterfacePacks | Sort-Object -Property FullName | Out-GridView -Title "Install.wim Language Interface Packs: Select Packages to apply and press OK (Esc or Cancel to Skip)" -PassThru
                if($null -eq $SelectedLanguageInterfacePacks) {Write-Warning "Install.wim Language Interface Packs: Skipping"}
            }
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim IsoExtract Language Features On Demand'
        #===================================================================================================
        $IsoExtractLanguageFeaturesOnDemand = @()
        if ($OSMedia.MajorVersion -eq 10) {
            $IsoExtractLanguageFeaturesOnDemand = $IsoExtractContent | Where-Object {$_.Name -like "*LanguageFeatures*"}
            if ($($OSMedia.Arch) -eq 'x86') {$IsoExtractLanguageFeaturesOnDemand = $IsoExtractLanguageFeaturesOnDemand | Where-Object {$_.Name -like "*x86*"}}
            if ($($OSMedia.Arch) -eq 'x64') {$IsoExtractLanguageFeaturesOnDemand = $IsoExtractLanguageFeaturesOnDemand | Where-Object {$_.Name -like "*x64*" -or $_.Name -like "*amd64*"}}
            if ($($OSMedia.ReleaseId)) {$IsoExtractLanguageFeaturesOnDemand = $IsoExtractLanguageFeaturesOnDemand | Where-Object {$_.FullName -like "*$($OSMedia.ReleaseId)*"}}
        <# if($null -eq $IsoExtractLanguageFeaturesOnDemand) {Write-Warning "IsoExtract Language Interface Packs: No compatible Packages were found in $OSBuilderContent\IsoExtract"}
            else {
                $IsoExtractLanguageFeaturesOnDemand = $IsoExtractLanguageFeaturesOnDemand | Out-GridView -Title "IsoExtract Language Features On Demand: Select Packages to apply and press OK (Esc or Cancel to Skip)" -PassThru
                if($null -eq $IsoExtractLanguageFeaturesOnDemand) {Write-Warning "IsoExtract Language Features On Demand: Skipping"}
            } #>

        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Updates Language Features On Demand'
        #===================================================================================================
        $UpdatesLanguageFeaturesOnDemand = @()
        $UpdatesLanguageFeaturesOnDemand = Get-ChildItem -Path "$OSBuilderContent\Updates\LanguageFeature" *.cab -Recurse | Select-Object -Property Name, FullName
        if ($($OSMedia.Arch) -eq 'x86') {$UpdatesLanguageFeaturesOnDemand = $UpdatesLanguageFeaturesOnDemand | Where-Object {$_.FullName -like "*x86*"}}
        if ($($OSMedia.Arch) -eq 'x64') {$UpdatesLanguageFeaturesOnDemand = $UpdatesLanguageFeaturesOnDemand | Where-Object {$_.FullName -like "*x64*" -or $_.FullName -like "*amd64*"}}
        if ($($OSMedia.ReleaseId)) {$UpdatesLanguageFeaturesOnDemand = $UpdatesLanguageFeaturesOnDemand | Where-Object {$_.FullName -like "*$($OSMedia.ReleaseId)*"}}
    <# $UpdatesLanguageFeaturesOnDemand = $UpdatesLanguageFeaturesOnDemand | Where-Object {$_.Name -ne 'lp.cab'}
        $UpdatesLanguageFeaturesOnDemand = $UpdatesLanguageFeaturesOnDemand | Where-Object {$_.Name -like "*LanguageFeatures*"} #>

        #$SelectedLanguageFeatures = $SelectedLanguageFeatures | Where-Object {$_.Name -like "*$($OSMedia.Arch)*"}
        
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Select Language Features On Demand'
        #===================================================================================================
        $SelectedLanguageFeaturesOnDemand  = @()
        if ($OSMedia.MajorVersion -eq 10) {
            $SelectedLanguageFeaturesOnDemand = $IsoExtractLanguageFeaturesOnDemand + $UpdatesLanguageFeaturesOnDemand
            foreach ($Package in $SelectedLanguageFeaturesOnDemand) {$Package.FullName = $($Package.FullName).replace("$OSBuilderContent\",'')}
            if ($null -eq $SelectedLanguageFeaturesOnDemand) {Write-Warning "Install.wim Language Features On Demand: Not Found"}
            else {
                $SelectedLanguageFeaturesOnDemand = $SelectedLanguageFeaturesOnDemand | Sort-Object -Property FullName | Out-GridView -Title "Install.wim Language Features On Demand: Select Packages to apply and press OK (Esc or Cancel to Skip)" -PassThru
                if($null -eq $SelectedLanguageFeaturesOnDemand) {Write-Warning "Install.wim Language Features On Demand: Skipping"}
            }
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim PowerShell Scripts'
        #===================================================================================================
        $SelectedScripts =@()
        $SelectedScripts = Get-ChildItem -Path "$OSBuilderContent\Scripts" *.ps1 | Select-Object -Property Name, FullName
        foreach ($Pack in $SelectedScripts) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        if ($null -eq $SelectedScripts) {Write-Warning "Install.wim PowerShell Scripts: Not Found"}
        else {
            $SelectedScripts = $SelectedScripts | Out-GridView -Title "Install.wim PowerShell Scripts: Select PowerShell Scripts to execute and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedScripts) {Write-Warning "Install.wim PowerShell Scripts: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Start Layout'
        #===================================================================================================
        $SelectedStartLayoutXML =@()
        if ($OSMedia.MajorVersion -eq 10) {
            $SelectedStartLayoutXML = Get-ChildItem -Path "$OSBuilderContent\StartLayout" *.xml | Select-Object -Property Name, FullName, Length, CreationTime | Sort-Object -Property FullName
            foreach ($Pack in $SelectedStartLayoutXML) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
            if ($null -eq $SelectedStartLayoutXML) {Write-Warning "Install.wim Start Layout: Not Found"}
            else {
                $SelectedStartLayoutXML = $SelectedStartLayoutXML | Out-GridView -Title "Install.wim Start Layout: Select a Start Layout XML to apply and press OK (Esc or Cancel to Skip)" -OutputMode Single
                if ($null -eq $SelectedStartLayoutXML) {Write-Warning "Install.wim Start Layout: Skipping"}
            }
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Unattend.xml'
        #===================================================================================================
        $SelectedUnattendXML =@()
        $SelectedUnattendXML = Get-ChildItem -Path "$OSBuilderContent\Unattend" *.xml | Select-Object -Property Name, FullName, Length, CreationTime | Sort-Object -Property FullName
        foreach ($Pack in $SelectedUnattendXML) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        if ($null -eq $SelectedUnattendXML) {Write-Warning "Install.wim Unattend.xml: Not Found"}
        else {
            $SelectedUnattendXML = $SelectedUnattendXML | Out-GridView -Title "Install.wim Unattend.xml: Select a Windows Unattend XML File to apply and press OK (Esc or Cancel to Skip)" -OutputMode Single
            if ($null -eq $SelectedUnattendXML) {Write-Warning "Install.wim Unattend.xml: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Windows Drivers'
        #===================================================================================================
        $SelectedDrivers =@()
        $SelectedDrivers = Get-ChildItem -Path "$OSBuilderContent\Drivers" -Directory | Select-Object -Property Name, FullName
        foreach ($Pack in $SelectedDrivers) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        if ($null -eq $SelectedDrivers) {Write-Warning "Install.wim Windows Drivers: Not Found"}
        else {
            $SelectedDrivers = $SelectedDrivers | Out-GridView -Title "Install.wim Windows Drivers: Select Driver Paths to apply and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedDrivers) {Write-Warning "Install.wim Windows Drivers: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Extra Files'
        #===================================================================================================
        $SelectedExtraFiles =@()
        $SelectedExtraFiles = Get-ChildItem -Path "$OSBuilderContent\ExtraFiles" -Directory | Select-Object -Property Name, FullName
        $SelectedExtraFiles = $SelectedExtraFiles | Where-Object {(Get-ChildItem $_.FullName | Measure-Object).Count -gt 0}
        foreach ($Pack in $SelectedExtraFiles) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        if ($null -eq $SelectedExtraFiles) {Write-Warning "Install.wim Extra Files: Not Found"}
        else {
            $SelectedExtraFiles = $SelectedExtraFiles | Out-GridView -Title "Install.wim Extra Files: Select directories to inject and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedExtraFiles) {Write-Warning "Install.wim Extra Files: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 Install.wim Windows Packages'
        #===================================================================================================
        $SelectedPackages =@()
        $SelectedPackages = Get-ChildItem -Path "$OSBuilderContent\Packages\*" -Include *.cab, *.msu -Recurse | Select-Object -Property Name, FullName
        $SelectedPackages = $SelectedPackages | Where-Object {$_.FullName -like "*$($OSMedia.Arch)*"}
        foreach ($Pack in $SelectedPackages) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        if ($null -eq $SelectedPackages) {Write-Warning "Install.wim Windows Packages: Not Found"}
        else {
            $SelectedPackages = $SelectedPackages | Out-GridView -Title "Install.wim Windows Packages: Select Packages to apply and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedPackages) {Write-Warning "Install.wim Windows Packages: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 WinPE DaRT'
        #===================================================================================================
        $SelectedWinPEDaRT =@()
        $SelectedWinPEDaRT = Get-ChildItem -Path "$OSBuilderContent\WinPE\DaRT" *.cab -Recurse | Select-Object -Property Name, FullName
        $SelectedWinPEDaRT = $SelectedWinPEDaRT | Where-Object {$_.FullName -like "*$($OSMedia.Arch)*"}
        foreach ($Pack in $SelectedWinPEDaRT) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        if ($null -eq $SelectedWinPEDaRT) {Write-Warning "WinPE DaRT: Not Found"}
        else {
            $SelectedWinPEDaRT = $SelectedWinPEDaRT | Out-GridView -Title "WinPE DaRT: Select a WinPE DaRT Package to apply and press OK (Esc or Cancel to Skip)" -OutputMode Single
            if ($null -eq $SelectedWinPEDaRT) {Write-Warning "WinPE DaRT: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 WinPE Drivers'
        #===================================================================================================
        $SelectedWinPEDrivers =@()
        $SelectedWinPEDrivers = Get-ChildItem -Path "$OSBuilderContent\WinPE\Drivers" -Directory | Select-Object -Property Name, FullName
        $SelectedWinPEDrivers = $SelectedWinPEDrivers | Where-Object {(Get-ChildItem $_.FullName | Measure-Object).Count -gt 0}
        foreach ($Pack in $SelectedWinPEDrivers) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        if ($null -eq $SelectedWinPEDrivers) {Write-Warning "WinPE Drivers: Not Found"}
        else {
            $SelectedWinPEDrivers = $SelectedWinPEDrivers | Out-GridView -Title "WinPE Drivers: Select WinPE Drivers to apply and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedWinPEDrivers) {Write-Warning "WinPE Drivers: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 WinSE.wim PowerShell Scripts'
        #===================================================================================================
        $SelectedWinPEScriptsSetup =@()
        $SelectedWinPEScriptsSetup = Get-ChildItem -Path "$OSBuilderContent\WinPE\Scripts" *.ps1 | Select-Object -Property Name, FullName
        foreach ($Pack in $SelectedWinPEScriptsSetup) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        if ($null -eq $SelectedWinPEScriptsSetup) {Write-Warning "WinSE.wim PowerShell Scripts: Not Found"}
        else {
            $SelectedWinPEScriptsSetup = $SelectedWinPEScriptsSetup | Out-GridView -Title "WinSE.wim PowerShell Scripts: Select PowerShell Scripts to execute and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedWinPEScriptsSetup) {Write-Warning "WinSE.wim PowerShell Scripts: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 WinPE.wim PowerShell Scripts'
        #===================================================================================================
        $SelectedWinPEScriptsPE =@()
        $SelectedWinPEScriptsPE = Get-ChildItem -Path "$OSBuilderContent\WinPE\Scripts" *.ps1 | Select-Object -Property Name, FullName
        foreach ($Pack in $SelectedWinPEScriptsPE) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        if ($null -eq $SelectedWinPEScriptsPE) {Write-Warning "WinPE.wim PowerShell Scripts: Not Found"}
        else {
            $SelectedWinPEScriptsPE = $SelectedWinPEScriptsPE | Out-GridView -Title "WinPE.wim PowerShell Scripts: Select PowerShell Scripts to execute and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedWinPEScriptsPE) {Write-Warning "WinPE.wim PowerShell Scripts: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 WinRE.wim PowerShell Scripts'
        #===================================================================================================
        $SelectedWinPEScriptsRE =@()
        $SelectedWinPEScriptsRE = Get-ChildItem -Path "$OSBuilderContent\WinPE\Scripts" *.ps1 | Select-Object -Property Name, FullName
        foreach ($Pack in $SelectedWinPEScriptsRE) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        if ($null -eq $SelectedWinPEScriptsRE) {Write-Warning "WinRE.wim PowerShell Scripts: Not Found"}
        else {
            $SelectedWinPEScriptsRE = $SelectedWinPEScriptsRE | Out-GridView -Title "WinRE.wim PowerShell Scripts: Select PowerShell Scripts to execute and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedWinPEScriptsRE) {Write-Warning "WinRE.wim PowerShell Scripts: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 WinSE.wim Extra Files'
        #===================================================================================================
        $SelectedWinPEExtraFilesSetup =@()
        $SelectedWinPEExtraFilesSetup = Get-ChildItem -Path "$OSBuilderContent\WinPE\ExtraFiles" -Directory | Select-Object -Property Name, FullName
        $SelectedWinPEExtraFilesSetup = $SelectedWinPEExtraFilesSetup | Where-Object {(Get-ChildItem $_.FullName | Measure-Object).Count -gt 0}
        foreach ($Pack in $SelectedWinPEExtraFilesSetup) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        if ($null -eq $SelectedWinPEExtraFilesSetup) {Write-Warning "WinSE.wim Extra Files: Not Found"}
        else {
            $SelectedWinPEExtraFilesSetup = $SelectedWinPEExtraFilesSetup | Out-GridView -Title "WinSE.wim Extra Files: Select Extra Files to apply and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedWinPEExtraFilesSetup) {Write-Warning "WinSE.wim Extra Files: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 WinPE.wim Extra Files'
        #===================================================================================================
        $SelectedWinPEExtraFilesPE =@()
        $SelectedWinPEExtraFilesPE = Get-ChildItem -Path "$OSBuilderContent\WinPE\ExtraFiles" -Directory | Select-Object -Property Name, FullName
        $SelectedWinPEExtraFilesPE = $SelectedWinPEExtraFilesPE | Where-Object {(Get-ChildItem $_.FullName | Measure-Object).Count -gt 0}
        foreach ($Pack in $SelectedWinPEExtraFilesPE) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        if ($null -eq $SelectedWinPEExtraFilesPE) {Write-Warning "WinPE.wim Extra Files: Not Found"}
        else {
            $SelectedWinPEExtraFilesPE = $SelectedWinPEExtraFilesPE | Out-GridView -Title "WinPE.wim Extra Files: Select Extra Files to apply and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedWinPEExtraFilesPE) {Write-Warning "WinPE.wim Extra Files: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 WinRE.wim Extra Files'
        #===================================================================================================
        $SelectedWinPEExtraFilesRE =@()
        $SelectedWinPEExtraFilesRE = Get-ChildItem -Path "$OSBuilderContent\WinPE\ExtraFiles" -Directory | Select-Object -Property Name, FullName
        $SelectedWinPEExtraFilesRE = $SelectedWinPEExtraFilesRE | Where-Object {(Get-ChildItem $_.FullName | Measure-Object).Count -gt 0}
        foreach ($Pack in $SelectedWinPEExtraFilesRE) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        if ($null -eq $SelectedWinPEExtraFilesRE) {Write-Warning "WinRE.wim Extra Files: Not Found"}
        else {
            $SelectedWinPEExtraFilesRE = $SelectedWinPEExtraFilesRE | Out-GridView -Title "WinRE.wim Extra Files: Select Extra Files to apply and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedWinPEExtraFilesRE) {Write-Warning "WinRE.wim Extra Files: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 WinSE.wim ADK Packages'
        #===================================================================================================
        $SelectedWinPEADKSetupPkgs =@()
        $SelectedWinPEADKSetupPkgs = Get-ChildItem -Path "$OSBuilderContent\WinPE\ADK" *.cab -Recurse | Select-Object -Property Name, FullName
        foreach ($Pack in $SelectedWinPEADKSetupPkgs) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        $SelectedWinPEADKSetupPkgs = $SelectedWinPEADKSetupPkgs | Where-Object {$_.FullName -like "*$($OSMedia.Arch)*"}
        $SelectedWinPEADKSetupPkgs = $SelectedWinPEADKSetupPkgs | Where-Object {$_.FullName -like "*$($OSMedia.ReleaseId)*"}
        if ($null -eq $SelectedWinPEADKSetupPkgs) {Write-Warning "WinSE.wim ADK Packages: Not Found"}
        else {
            $SelectedWinPEADKSetupPkgs = $SelectedWinPEADKSetupPkgs | Out-GridView -Title "WinSE.wim ADK Packages: Select ADK Packages to apply and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedWinPEADKSetupPkgs) {Write-Warning "WinSE.wim ADK Packages: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 WinPE.wim ADK Packages'
        #===================================================================================================
        $SelectedWinPEADKPEPkgs =@()
        $SelectedWinPEADKPEPkgs = Get-ChildItem -Path "$OSBuilderContent\WinPE\ADK" *.cab -Recurse | Select-Object -Property Name, FullName
        foreach ($Pack in $SelectedWinPEADKPEPkgs) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        $SelectedWinPEADKPEPkgs = $SelectedWinPEADKPEPkgs | Where-Object {$_.FullName -like "*$($OSMedia.Arch)*"}
        $SelectedWinPEADKPEPkgs = $SelectedWinPEADKPEPkgs | Where-Object {$_.FullName -like "*$($OSMedia.ReleaseId)*"}
        if ($null -eq $SelectedWinPEADKPEPkgs) {Write-Warning "WinPE.wim ADK Packages: Not Found"}
        else {
            $SelectedWinPEADKPEPkgs = $SelectedWinPEADKPEPkgs | Out-GridView -Title "WinPE.wim ADK Packages: Select ADK Packages to apply and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedWinPEADKPEPkgs) {Write-Warning "WinPE.wim ADK Packages: Skipping"}
        }
        
        #===================================================================================================
        Write-Verbose '19.1.1 WinRE.wim ADK Packages'
        #===================================================================================================
        $SelectedWinPEADKREPkgs =@()
        $SelectedWinPEADKREPkgs = Get-ChildItem -Path "$OSBuilderContent\WinPE\ADK" *.cab -Recurse | Select-Object -Property Name, FullName
        foreach ($Pack in $SelectedWinPEADKREPkgs) {$Pack.FullName = $($Pack.FullName).replace("$OSBuilderContent\",'')}
        $SelectedWinPEADKREPkgs = $SelectedWinPEADKREPkgs | Where-Object {$_.FullName -like "*$($OSMedia.Arch)*"}
        $SelectedWinPEADKREPkgs = $SelectedWinPEADKREPkgs | Where-Object {$_.FullName -like "*$($OSMedia.ReleaseId)*"}
        if ($null -eq $SelectedWinPEADKREPkgs) {Write-Warning "WinRE.wim ADK Packages: Not Found"}
        else {
            $SelectedWinPEADKREPkgs = $SelectedWinPEADKREPkgs | Out-GridView -Title "WinRE.wim ADK Packages: Select ADK Packages to apply and press OK (Esc or Cancel to Skip)" -PassThru
            if ($null -eq $SelectedWinPEADKREPkgs) {
                Write-Warning "WinRE.wim ADK Packages: Skipping"}
            else {
                Write-Warning "If you add too many ADK Packages to WinRE, like .Net and PowerShell"
                Write-Warning "You run a risk of your WinRE size increasing considerably"
                Write-Warning "If your MBR System or UEFI Recovery Partition are 500MB,"
                Write-Warning "your WinRE.wim should not be more than 400MB (100MB Free)"
                Write-Warning "Consider changing your Task Sequences to have a 984MB"
                Write-Warning "MBR System or UEFI Recovery Partition"
            }
        }
        
        if ($OSMedia.MajorVersion -eq 6) {$EnableNetFX3 = $false}

        #===================================================================================================
        Write-Verbose '19.1.1 Build Task'
        #===================================================================================================
        $Task = [ordered]@{
            "TaskType" = [string]"OSBuild";
            "TaskName" = [string]$TaskName;
            "TaskVersion" = [string]$($(Get-Module -Name OSBuilder).Version);
            "TaskGuid" = [string]$(New-Guid);
            
            "CustomName" = [string]$CustomName;

            "OSMFamily" = [string]$OSMedia.OSMFamily;
            "OSMGuid" = [string]$OSMedia.OSMGuid;
            "Name" = [string]$OSMedia.Name;
            "ImageName" = [string]$OSMedia.ImageName;
            "Arch" = [string]$OSMedia.Arch;
            "ReleaseId" = [string]$($OSMedia.ReleaseId);
            "UBR" = [string]$OSMedia.UBR;
            "EditionId" = [string]$OSMedia.EditionId;
            "InstallationType" = [string]$OSMedia.InstallationType;
            "MajorVersion" = [string]$OSMedia.MajorVersion;
            "Build" = [string]$OSMedia.Build;
            "CreatedTime" = [datetime]$OSMedia.CreatedTime;
            "ModifiedTime" = [datetime]$OSMedia.ModifiedTime;

            "EnableNetFX3" = [string]$EnableNetFX3;
            "StartLayoutXML" = [string]$SelectedStartLayoutXML.FullName;
            "UnattendXML" = [string]$SelectedUnattendXML.FullName;
            "WinPEAutoExtraFiles" = [string]$WinPEAutoExtraFiles;
            "WinPEAddDaRT" = [string]$SelectedWinPEDaRT.FullName;

            "ExtraFiles" = [string[]]$SelectedExtraFiles.FullName;
            "Scripts" = [string[]]$SelectedScripts.FullName;
            "Drivers" = [string[]]$SelectedDrivers.FullName;

            "AddWindowsPackage" = [string[]]$SelectedPackages.FullName;
            "RemoveWindowsPackage" = [string[]]$GetWindowsPackage.PackageName;
            "AddFeatureOnDemand" = [string[]]$SelectedFeaturesOnDemand.FullName;
            "EnableWindowsOptionalFeature" = [string[]]$EnableWinOptionalFeature.FeatureName;
            "DisableWindowsOptionalFeature" = [string[]]$DisableWinOptionalFeature.FeatureName;
            "RemoveAppxProvisionedPackage" = [string[]]$GetAppxProvisionedPackage.PackageName;
            "RemoveWindowsCapability" = [string[]]$GetWindowsCapability.Name;

            "WinPEDrivers" = [string[]]$SelectedWinPEDrivers.FullName;
            "WinPEScriptsPE" = [string[]]$SelectedWinPEScriptsPE.FullName;
            "WinPEScriptsRE" = [string[]]$SelectedWinPEScriptsRE.FullName;
            "WinPEScriptsSE" = [string[]]$SelectedWinPEScriptsSetup.FullName
            "WinPEExtraFilesPE" = [string[]]$SelectedWinPEExtraFilesPE.FullName;
            "WinPEExtraFilesRE" = [string[]]$SelectedWinPEExtraFilesRE.FullName;
            "WinPEExtraFilesSE" = [string[]]$SelectedWinPEExtraFilesSetup.FullName;
            "WinPEADKPE" = [string[]]$SelectedWinPEADKPEPkgs.FullName;
            "WinPEADKRE" = [string[]]$SelectedWinPEADKREPkgs.FullName;
            "WinPEADKSE" = [string[]]$SelectedWinPEADKSetupPkgs.FullName;

            "LangSetAllIntl" = [string]$SetAllIntl;
            "LangSetInputLocale" = [string]$SetInputLocale;
            "LangSetSKUIntlDefaults" = [string]$SetSKUIntlDefaults;
            "LangSetSetupUILang" = [string]$SetSetupUILang;
            "LangSetSysLocale" = [string]$SetSysLocale;
            "LangSetUILang" = [string]$SetUILang;
            "LangSetUILangFallback" = [string]$SetUILangFallback;
            "LangSetUserLocale" = [string]$SetUserLocale;
            "LanguageFeature" = [string[]]$SelectedLanguageFeaturesOnDemand.FullName;
            "LanguageInterfacePack" = [string[]]$SelectedLanguageInterfacePacks.FullName;
            "LanguagePack" = [string[]]$SelectedLanguagePacks.FullName;
        }

        #===================================================================================================
        Write-Verbose '19.1.1 New-OSBuildTask Complete'
        #===================================================================================================
        Write-Host '========================================================================================' -ForegroundColor DarkGray
        Write-Host "OSBuild Task: $TaskName" -ForegroundColor Green
        $Task | ConvertTo-Json | Out-File "$TaskPath"
        $Task
    }

    END {
        #Write-Host '========================================================================================' -ForegroundColor DarkGray
        #Write-Host "$($MyInvocation.MyCommand.Name) END" -ForegroundColor Green
    }
}