Public/New-OSDCloudOSMedia.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
function New-OSDCloudOSMedia {
    [CmdletBinding()]
    param (
        #Pauses the function the Install.wim is dismounted
        #Useful for Testing
        [Alias('PauseOS','PauseDismount')]
        [switch]$PauseDismountOS,

        #Pauses the function before WinPE is dismounted
        #Useful for Testing
        [Alias('PausePE')]
        [switch]$PauseDismountPE
    )

    Begin {
        #=======================================================================
        # Get-OSDBuilder
        #=======================================================================
        Get-OSDBuilder -CreatePaths -HideDetails
        #=======================================================================
        # Block
        #=======================================================================
        Block-WinPE
        Block-StandardUser
        Block-WindowsVersionNe10
        Block-PowerShellVersionLt5
        Block-NoCurl
        #=======================================================================
    }

    Process {
        Write-Host '========================================================================================' -ForegroundColor DarkGray
        Write-Host -ForegroundColor Green "$($MyInvocation.MyCommand.Name) PROCESS"
        Write-Verbose "MyInvocation.MyCommand.Name: $($MyInvocation.MyCommand.Name)"
        Write-Verbose "PSCmdlet.ParameterSetName: $($PSCmdlet.ParameterSetName)"
        #=======================================================================
        # OSDCloud
        #=======================================================================
        $BirdBox = @()
        $BirdBox = Get-OSMedia -OSMajorVersion 10 | Where-Object {$_.MediaType -eq 'OSImport'} | Where-Object {$_.RegBuild -ge 19041}

        $BirdBox = $BirdBox | Out-GridView -PassThru -Title "Select one or more OSImport to Build (Cancel to Exit) and press OK"

        if ($null -eq $BirdBox) {
            Write-Warning "Could not find a matching OSImport . . . Exiting!"
            Return
        }

        foreach ($Bird in $BirdBox) {
            #=======================================================================
            # Set Paths
            #=======================================================================
            if (Test-Path "$SetOSDBuilderPathOSImport\$($Bird.Name)") {$OSMediaPath = "$SetOSDBuilderPathOSImport\$($Bird.Name)"}
            $OSImagePath = "$OSMediaPath\OS\sources\install.wim"

            if (!(Test-Path "$OSMediaPath\WindowsImage.txt")) {
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                if ($null -eq $OSMediaPath) {
                    Write-Warning "Unable to find an OSMedia to use"
                } else {
                    Write-Warning "$OSMediaPath is not a valid OSMedia Directory"
                }
                Return
            }

            if (!(Test-Path "$OSImagePath")) {
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Warning "$OSImagePath is not a valid Windows Image"
                Return
            }
            #=======================================================================
            # Get Windows Image Information
            #=======================================================================
            $OSImageIndex = 1
            $WindowsImage = Get-WindowsImage -ImagePath "$OSImagePath" -Index $OSImageIndex | Select-Object -Property *

            $OSImageName = ($WindowsImage).ImageName
            $OSImageName = $OSImageName -replace '\(', ''
            $OSImageName = $OSImageName -replace '\)', ''

            $OSImageDescription = ($WindowsImage).ImageDescription

            $OSArchitecture = $($WindowsImage.Architecture)
            if ($OSArchitecture -eq '0') {$OSArchitecture = 'x86'}
            if ($OSArchitecture -eq '6') {$OSArchitecture = 'ia64'}
            if ($OSArchitecture -eq '9') {$OSArchitecture = 'x64'}
            if ($OSArchitecture -eq '12') {$OSArchitecture = 'x64 ARM'}

            $OSEditionID =          $($WindowsImage.EditionId)
            $OSInstallationType =   $($WindowsImage.InstallationType)
            $OSLanguages =          $($WindowsImage.Languages)
            $OSVersion =            $($WindowsImage.Version)
            $OSMajorVersion =       $($WindowsImage.MajorVersion)
            $OSMinorVersion =       $($WindowsImage.MinorVersion)
            $OSBuild =              $($WindowsImage.Build)
            $OSSPBuild =            $($WindowsImage.SPBuild)
            $OSSPLevel =            $($WindowsImage.SPLevel)
            $OSImageBootable =      $($WindowsImage.ImageBootable)
            $OSWIMBoot =            $($WindowsImage.WIMBoot)
            $OSCreatedTime =        $($WindowsImage.CreatedTime)
            $OSModifiedTime =       $($WindowsImage.ModifiedTime)

            Show-MediaImageInfoOS
            #=======================================================================
            # Get Adk Paths
            #=======================================================================
            if ($OSArchitecture -eq 'x64') {
                $AdkPaths = Get-AdkPaths -Arch 'amd64'
            }
            else {
                $AdkPaths = Get-AdkPaths -Arch 'x86'
            }
    
            if ($null -eq $AdkPaths) {
                Write-Host -ForegroundColor DarkGray "========================================================================="
                Write-Warning "Could not get ADK going, sorry"
                Write-Host -ForegroundColor DarkGray "========================================================================="
                Break
            }
            #=======================================================================
            # ADK Packages
            #=======================================================================
            $ErrorActionPreference = 'Ignore'
            $WinPEOCs = $AdkPaths.WinPEOCs
    
            $OCPackages = @(
                'WMI'
                'HTA'
                'NetFx'
                'Scripting'
                'PowerShell'
                'SecureStartup'
                'DismCmdlets'
                'Dot3Svc'
                'EnhancedStorage'
                'FMAPI'
                'GamingPeripherals'
                'PPPoE'
                'PlatformId'
                'PmemCmdlets'
                'RNDIS'
                'SecureBootCmdlets'
                'StorageWMI'
                'WDS-Tools'
            )
            #=======================================================================
            # Validate Registry CurrentVersion.xml'
            #=======================================================================
            $RegValueCurrentBuild = $null
            if (Test-Path "$OSMediaPath\info\xml\CurrentVersion.xml") {
                $RegKeyCurrentVersion = Import-Clixml -Path "$OSMediaPath\info\xml\CurrentVersion.xml"
                
                [string]$RegValueCurrentBuild = ($RegKeyCurrentVersion).CurrentBuild
                [string]$RegValueDisplayVersion = ($RegKeyCurrentVersion).DisplayVersion
                [string]$ReleaseId = ($RegKeyCurrentVersion).ReleaseId
                if ($RegValueDisplayVersion) {$ReleaseId = $RegValueDisplayVersion}
            }
            #=======================================================================
            Write-Verbose '19.1.1 Set ReleaseId'
            #=======================================================================
            if ($null -ne $RegValueCurrentBuild) {$OSBuild = $RegValueCurrentBuild}
            if ($null -eq $ReleaseId) {
                if ($OSBuild -eq 7600) {$ReleaseId = 7600}
                if ($OSBuild -eq 7601) {$ReleaseId = 7601}
                if ($OSBuild -eq 9600) {$ReleaseId = 9600}
                if ($OSBuild -eq 10240) {$ReleaseId = 1507}
                if ($OSBuild -eq 14393) {$ReleaseId = 1607}
                if ($OSBuild -eq 15063) {$ReleaseId = 1703}
                if ($OSBuild -eq 16299) {$ReleaseId = 1709}
                if ($OSBuild -eq 17134) {$ReleaseId = 1803}
                if ($OSBuild -eq 17763) {$ReleaseId = 1809}
                #if ($OSBuild -eq 18362) {$ReleaseId = 1903}
                #if ($OSBuild -eq 18363) {$ReleaseId = 1909}
                #if ($OSBuild -eq 19041) {$ReleaseId = 2004}
                #if ($OSBuild -eq 19042) {$ReleaseId = '20H2'}
                #if ($OSBuild -eq 19043) {$ReleaseId = '21H1'}
                #if ($OSBuild -eq 19044) {$ReleaseId = '21H2'}
            }

            Write-Verbose "ReleaseId: $ReleaseId"
            Write-Verbose "CurrentBuild: $RegValueCurrentBuild"
            #=================================================
            # Operating System
            #=================================================
            $UpdateOS = ''
            if ($OSMajorVersion -eq 10) {
                if ($OSInstallationType -match 'Server') {
                    $UpdateOS = 'Windows Server'
                }
                else {
                    if ($OSImageName -match ' 11 ') {
                        $UpdateOS = 'Windows 11'
                    }
                    else {
                        $UpdateOS = 'Windows 10'
                    }
                }
            }
            #=======================================================================
            #WorkingName and WorkingPath'
            #=======================================================================
            if ($Bird.Name -match 'OSDCloud') {
                $WorkingName = $Bird.Name
            }
            else {
                $WorkingName = "$($Bird.Name) OSDCloud"
            }
            $WorkingPath = "$SetOSDBuilderPathOSMedia\$WorkingName"
            #=======================================================================
            Write-Verbose '19.1.1 Remove Existing OSMedia'
            #=======================================================================
            if (Test-Path $WorkingPath) {
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Warning "$WorkingPath will be replaced!"
            }
            #=======================================================================
            Write-Verbose '19.1.25 Remove Existing WorkingPath'
            #=======================================================================
            if (Test-Path $WorkingPath) {
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                Remove-Item -Path "$WorkingPath" -Force -Recurse
            }
            #=======================================================================
            Write-Verbose '19.2.25 Set Variables'
            #=======================================================================
            $MountDirectory = Join-Path $SetOSDBuilderPathMount "os$((Get-Date).ToString('yyMMddhhmm'))"
            $MountWinPE = Join-Path $SetOSDBuilderPathMount "winpe$((Get-Date).ToString('yyMMddhhmm'))"
            $MountWinRE = Join-Path $SetOSDBuilderPathMount "winre$((Get-Date).ToString('yyMMddhhmm'))"
            $MountWinSE = Join-Path $SetOSDBuilderPathMount "setup$((Get-Date).ToString('yyMMddhhmm'))"
            $Info = Join-Path $WorkingPath 'info'
                $Logs = Join-Path $Info 'logs'
            $OS = Join-Path $WorkingPath 'OS'
            $WimTemp = Join-Path $WorkingPath "WimTemp"
            $WinPE = Join-Path $WorkingPath 'WinPE'
                $PEInfo = Join-Path $WinPE 'info'
                $PELogs = Join-Path $PEInfo 'logs'
            #=======================================================================
            # Start Transcript
            #=======================================================================
            $ScriptName = $($MyInvocation.MyCommand.Name)
            $LogName = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$ScriptName.log"
            Start-Transcript -Path (Join-Path "$Info\logs" $LogName) | Out-Null
            #=======================================================================
            # Update-OSMedia and New-OSBuild
            #=======================================================================
            New-DirectoriesOSMedia
            Show-WorkingInfoOS
            Copy-MediaOperatingSystem
            #=======================================================================
            # Mount WinPE
            #=======================================================================
            Mount-WinPEwim -OSMediaPath "$WorkingPath"
            Mount-WinREwim -OSMediaPath "$WorkingPath"
            Mount-WinSEwim -OSMediaPath "$WorkingPath"
            #=======================================================================
            # WinPE ADK
            #=======================================================================
            $TemplateLogs = $Logs

            Write-Host -ForegroundColor DarkGray "========================================================================="
            Write-Host -ForegroundColor Cyan "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Adding default en-US ADK Packages"
            Write-Host -ForegroundColor Yellow "Dism Function: Add-WindowsPackage"
            $Lang = 'en-us'

            foreach ($Package in $OCPackages) {
                $SourceFile = "$WinPEOCs\WinPE-$Package.cab"
                if (Test-Path $SourceFile) {
                    Write-Host -ForegroundColor DarkGray "$SourceFile"
                    $PackageName = "Add-WindowsPackage-WinPE-$Package"

                    $CurrentLog = "$TemplateLogs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$PackageName WinPE.log"
                    Try {Add-WindowsPackage -Path $MountWinPE -PackagePath $SourceFile -LogPath "$CurrentLog" | Out-Null}
                    Catch {Write-Host -ForegroundColor Red $CurrentLog}
                    
                    $CurrentLog = "$TemplateLogs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$PackageName WinRE.log"
                    Try {Add-WindowsPackage -Path $MountWinRE -PackagePath $SourceFile -LogPath "$CurrentLog" | Out-Null}
                    Catch {Write-Host -ForegroundColor Red $CurrentLog}
                    
                    $CurrentLog = "$TemplateLogs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$PackageName WinSE.log"
                    Try {Add-WindowsPackage -Path $MountWinSE -PackagePath $SourceFile -LogPath "$CurrentLog" | Out-Null}
                    Catch {Write-Host -ForegroundColor Red $CurrentLog}
                }
            }

            $SourceFile = "$WinPEOCs\$Lang\lp.cab"
            if (Test-Path $SourceFile) {
                Write-Host -ForegroundColor DarkGray "$SourceFile"
                $PackageName = "Add-WindowsPackage-WinPE-lp_$Lang"

                $CurrentLog = "$TemplateLogs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$PackageName WinPE.log"
                Try {Add-WindowsPackage -Path $MountWinPE -PackagePath $SourceFile -LogPath "$CurrentLog" | Out-Null}
                Catch {Write-Host -ForegroundColor Red $CurrentLog}

                $CurrentLog = "$TemplateLogs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$PackageName WinRE.log"
                Try {Add-WindowsPackage -Path $MountWinRE -PackagePath $SourceFile -LogPath "$CurrentLog" | Out-Null}
                Catch {Write-Host -ForegroundColor Red $CurrentLog}

                $CurrentLog = "$TemplateLogs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$PackageName WinSE.log"
                Try {Add-WindowsPackage -Path $MountWinSE -PackagePath $SourceFile -LogPath "$CurrentLog" | Out-Null}
                Catch {Write-Host -ForegroundColor Red $CurrentLog}
            }
            else {
                Write-Warning "Could not find $SourceFile"
            }

            foreach ($Package in $OCPackages) {
                $SourceFile = "$WinPEOCs\$Lang\WinPE-$Package`_$Lang.cab"
                if (Test-Path $SourceFile) {
                    Write-Host -ForegroundColor DarkGray "$SourceFile"
                    $PackageName = "Add-WindowsPackage-WinPE-$Package`_$Lang"
                    $CurrentLog = "$TemplateLogs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$PackageName WinPE.log"
                    Try {Add-WindowsPackage -Path $MountWinPE -PackagePath $SourceFile -LogPath "$CurrentLog" | Out-Null}
                    Catch {Write-Host -ForegroundColor Red $CurrentLog}

                    $CurrentLog = "$TemplateLogs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$PackageName WinRE.log"
                    Try {Add-WindowsPackage -Path $MountWinRE -PackagePath $SourceFile -LogPath "$CurrentLog" | Out-Null}
                    Catch {Write-Host -ForegroundColor Red $CurrentLog}

                    $CurrentLog = "$TemplateLogs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$PackageName WinSE.log"
                    Try {Add-WindowsPackage -Path $MountWinSE -PackagePath $SourceFile -LogPath "$CurrentLog" | Out-Null}
                    Catch {Write-Host -ForegroundColor Red $CurrentLog}
                }
            }
            #=======================================================================
            # Save-WindowsImage
            #=======================================================================
            Write-Host -ForegroundColor DarkGray "========================================================================="
            Write-Host -ForegroundColor Cyan "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Save Windows Image"
            Write-Host -ForegroundColor Yellow "Dism Function: Save-WindowsImage"

            $CurrentLog = "$TemplateLogs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Save-WindowsImage.log"
            Save-WindowsImage -Path $MountWinPE -LogPath $CurrentLog | Out-Null

            $CurrentLog = "$TemplateLogs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Save-WindowsImage.log"
            Save-WindowsImage -Path $MountWinRE -LogPath $CurrentLog | Out-Null

            $CurrentLog = "$TemplateLogs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Save-WindowsImage.log"
            Save-WindowsImage -Path $MountWinSE -LogPath $CurrentLog | Out-Null
            #=======================================================================
            # WinPE DaRT
            #=======================================================================
            Write-Host -ForegroundColor DarkGray "========================================================================="
            Write-Host -ForegroundColor Cyan "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Microsoft DaRT"
            $SourceFile = "C:\Program Files\Microsoft DaRT\v10\Tools$OSArchitecture.cab"
            if (Test-Path $SourceFile) {
                Write-Host -ForegroundColor DarkGray $SourceFile
                expand.exe "$SourceFile" -F:*.* "$MountWinPE" | Out-Null
                expand.exe "$SourceFile" -F:*.* "$MountWinRE" | Out-Null
                expand.exe "$SourceFile" -F:*.* "$MountWinSE" | Out-Null

                $SourceFile = "C:\Program Files\Microsoft Deployment Toolkit\Templates\DartConfig8.dat"
                if (Test-Path $SourceFile) {
                    Write-Host -ForegroundColor DarkGray $SourceFile
                    Copy-Item -Path $SourceFile -Destination "$MountWinPE\Windows\System32\DartConfig.dat" -Force
                    Copy-Item -Path $SourceFile -Destination "$MountWinRE\Windows\System32\DartConfig.dat" -Force
                    Copy-Item -Path $SourceFile -Destination "$MountWinSE\Windows\System32\DartConfig.dat" -Force
                }
                else {
                    Write-Warning "Could not find $SourceFile"
                }
            }
            else {
                Write-Warning "Could not find $SourceFile"
            }

            if (Test-Path "$MountWinPE\Windows\System32\winpeshl.ini") {Remove-Item -Path "$MountWinPE\Windows\System32\winpeshl.ini" -Force}
            (Get-Content "$MountWinRE\Windows\System32\winpeshl.ini") | ForEach-Object {$_ -replace '-prompt','-network'} | Out-File "$MountWinRE\Windows\System32\winpeshl.ini"
            if (Test-Path "$MountWinSE\Windows\System32\winpeshl.ini") {Remove-Item -Path "$MountWinSE\Windows\System32\winpeshl.ini" -Force}
            #=======================================================================
            # WinPE Content
            #=======================================================================
            $WinPEAutoExtraFiles = $true
            Import-AutoExtraFilesPE

            $WinPEOSDCloud = $true
            Enable-WinPEOSDCloud
            
            $WinREWiFi = $true
            Enable-WinREWiFi
            #=======================================================================
            # Update-OSMedia and New-OSBuild
            #=======================================================================
            Save-PackageInventoryPE -OSMediaPath "$WorkingPath"
            if ($PauseDismountPE.IsPresent){[void](Read-Host 'Press Enter to Continue')}
            Dismount-WimsPE -OSMediaPath "$WorkingPath"
            Export-PEWims -OSMediaPath "$WorkingPath"
            Export-PEBootWim -OSMediaPath "$WorkingPath"
            Save-InventoryPE -OSMediaPath "$WorkingPath"
            #=======================================================================
            # Install.wim
            #=======================================================================
            $global:ReapplyLCU = $false
            Mount-InstallwimOS
            Set-WinREWimOS
            #=======================================================================
            # Install.wim UBR Pre-Update
            #=======================================================================
            Show-ActionTime
            Write-Host -ForegroundColor Green "OS: Mount Registry for UBR Information"
            $RegKeyCurrentVersion = Get-RegCurrentVersion -Path $MountDirectory

            $RegValueDisplayVersion = ($RegKeyCurrentVersion).DisplayVersion
            $ReleaseId = ($RegKeyCurrentVersion).ReleaseId
            if ($RegValueDisplayVersion) {$ReleaseId = $RegValueDisplayVersion}

            if ($($RegKeyCurrentVersion.CurrentBuild)) {$RegValueCurrentBuild = $($RegKeyCurrentVersion.CurrentBuild)}
            else {$RegValueCurrentBuild = $OSSPBuild}
            if ($($RegKeyCurrentVersion.UBR)) {$RegValueUbr = $($RegKeyCurrentVersion.UBR)}
            else {$RegValueUbr = $OSSPBuild}
            $UBR = "$RegValueCurrentBuild.$RegValueUbr"
            Save-RegistryCurrentVersionOS
            $UBRPre = $UBR
            #=======================================================================
            # Optional Content
            #=======================================================================
            Add-ContentPack -PackType OSCapability
            Add-ContentPack -PackType OSPackages
            Add-WindowsPackageOS
            Add-FeaturesOnDemandOS
            #=======================================================================
            # Install.wim UBR Post-Update
            #=======================================================================
            $RegKeyCurrentVersion = Get-RegCurrentVersion -Path $MountDirectory

            $RegValueDisplayVersion = ($RegKeyCurrentVersion).DisplayVersion
            $ReleaseId = ($RegKeyCurrentVersion).ReleaseId
            if ($RegValueDisplayVersion) {$ReleaseId = $RegValueDisplayVersion}

            if ($($RegKeyCurrentVersion.CurrentBuild)) {$RegValueCurrentBuild = $($RegKeyCurrentVersion.CurrentBuild)}
            else {$RegValueCurrentBuild = $OSSPBuild}
            if ($($RegKeyCurrentVersion.UBR)) {$RegValueUbr = $($RegKeyCurrentVersion.UBR)}
            else {$RegValueUbr = $OSSPBuild}
            $UBR = "$RegValueCurrentBuild.$RegValueUbr"
            Save-RegistryCurrentVersionOS
            Show-ActionTime
            Write-Host -ForegroundColor Green "OS: Update Build Revision $UBR (Post-LCU)"
            #=======================================================================
            # OneDriveSetup
            #=======================================================================
            if ($OSMajorVersion -eq 10 -and $OSInstallationType -eq 'Client') {
                Show-ActionTime
                Write-Host -ForegroundColor Green "OS: Update OneDriveSetup.exe"
                $OneDriveSetupDownload = $false
                $OneDriveSetup = Join-Path $GetOSDBuilderPathContentOneDrive 'OneDriveSetup.exe'
                if (!(Test-Path $OneDriveSetup)) {$OneDriveSetupDownload = $true}

                if (Test-Path $OneDriveSetup) {
                    if (!(([System.Io.fileinfo]$OneDriveSetup).LastWriteTime.Date -ge [datetime]::Today )) {
                        $OneDriveSetupDownload = $true
                    }
                }
<# if ($OneDriveSetupDownload -eq $true) {
                    $WebClient = New-Object System.Net.WebClient
                    Write-Host "Downloading to $OneDriveSetup" -ForegroundColor Gray
                    $WebClient.DownloadFile('https://go.microsoft.com/fwlink/p/?LinkId=248256',"$OneDriveSetup")
                } #>


                if ($OSArchitecture -eq 'x86') {
                    $OneDriveSetupInfo = Get-Item -Path "$MountDirectory\Windows\System32\OneDriveSetup.exe" | Select-Object -Property *
                    Write-Host -ForegroundColor Gray " Existing Image Version $($($OneDriveSetupInfo).VersionInfo.ProductVersion)"
                    if (Test-Path $OneDriveSetup) {
                        robocopy "$GetOSDBuilderPathContentOneDrive" "$MountDirectory\Windows\System32" OneDriveSetup.exe /ndl /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-OneDriveSetup.log" | Out-Null
                        $OneDriveSetupInfo = Get-Item -Path "$MountDirectory\Windows\System32\OneDriveSetup.exe" | Select-Object -Property *
                        Write-Host -ForegroundColor Gray " Updating with Version $($($OneDriveSetupInfo).VersionInfo.ProductVersion)"
                    }
                } else {
                    $OneDriveSetupInfo = Get-Item -Path "$MountDirectory\Windows\SysWOW64\OneDriveSetup.exe" | Select-Object -Property *
                    Write-Host -ForegroundColor Gray " Existing Image Version $($($OneDriveSetupInfo).VersionInfo.ProductVersion)"
                    if (Test-Path $OneDriveSetup) {
                        robocopy "$GetOSDBuilderPathContentOneDrive" "$MountDirectory\Windows\SysWOW64" OneDriveSetup.exe /ndl /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-OneDriveSetup.log" | Out-Null
                        $OneDriveSetupInfo = Get-Item -Path "$MountDirectory\Windows\SysWOW64\OneDriveSetup.exe" | Select-Object -Property *
                        Write-Host -ForegroundColor Gray " Updating with Version $($($OneDriveSetupInfo).VersionInfo.ProductVersion)"
                    }
                }
                Write-Host -ForegroundColor Cyan " To update OneDriveSetup.exe use one of the following commands:"
                Write-Host -ForegroundColor Cyan " Save-OSDBuilderDownload -ContentDownload 'OneDriveSetup Enterprise'"
                Write-Host -ForegroundColor Cyan " Save-OSDBuilderDownload -ContentDownload 'OneDriveSetup Production'"
            }
            #=======================================================================
            # Content
            #=======================================================================
            Enable-WindowsOptionalFeatureOS
            Enable-NetFXOS
            Remove-AppxProvisionedPackageOS
            Remove-WindowsPackageOS
            Remove-WindowsCapabilityOS
            Disable-WindowsOptionalFeatureOS
            Add-ContentDriversOS
            Add-ContentExtraFilesOS
            Add-ContentStartLayout
            Add-ContentUnattend
            Add-ContentScriptsOS
            Import-RegistryRegOS
            Import-RegistryXmlOS
            Add-ContentPack -PackType OSDrivers
            Add-ContentPack -PackType OSExtraFiles
            Add-ContentPack -PackType OSPoshMods
            Add-ContentPack -PackType OSRegistry
            Add-ContentPack -PackType OSScripts
            Add-ContentPack -PackType OSStartLayout
            #=======================================================================
            # Mirror OSMedia and OSBuild
            #=======================================================================
            Save-AutoExtraFilesOS -OSMediaPath "$WorkingPath"
            Save-SessionsXmlOS -OSMediaPath "$WorkingPath"
            Save-InventoryOS -OSMediaPath "$WorkingPath"
            #=======================================================================
            # Dismount
            #=======================================================================
            if ($PauseDismountOS.IsPresent){[void](Read-Host 'Press Enter to Continue')}
            Dismount-InstallwimOS
            Export-InstallwimOS
            #=======================================================================
            Write-Verbose '19.1.1 OS: Export Configuration'
            #=======================================================================
            Show-ActionTime
            Write-Host -ForegroundColor Green "OS: Export Configuration to $WorkingPath\WindowsImage.txt"
            $GetWindowsImage = @()
            $GetWindowsImage = Get-WindowsImage -ImagePath "$OS\sources\install.wim" -Index 1 | Select-Object -Property *

            Write-Verbose "========== SPBuild: $($GetWindowsImage.Build).$($GetWindowsImage.SPBuild)"
            if ($OSVersion -like "6.*") {
                Write-Verbose '========== Windows 6.x'
                $UBR = "$($GetWindowsImage.Build).$($GetWindowsImage.SPBuild)"
            }
            Write-Verbose "========== UBR: $UBR"

            $GetWindowsImage | Add-Member -Type NoteProperty -Name "UBR" -Value $UBR
            $GetWindowsImage | Out-File "$WorkingPath\WindowsImage.txt"
            $GetWindowsImage | Out-File "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage.txt"
            $GetWindowsImage | Export-Clixml -Path "$Info\xml\Get-WindowsImage.xml"
            $GetWindowsImage | Export-Clixml -Path "$Info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage.xml"
            $GetWindowsImage | ConvertTo-Json | Out-File "$Info\json\Get-WindowsImage.json"
            $GetWindowsImage | ConvertTo-Json | Out-File "$Info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage.json"
            (Get-Content "$WorkingPath\WindowsImage.txt") | Where-Object {$_.Trim(" `t")} | Set-Content "$WorkingPath\WindowsImage.txt"
            #=======================================================================
            # OSD-Export
            #=======================================================================
            #Save-WindowsImageContentPE
            #=======================================================================
            Write-Verbose '19.3.17 UBR Validation'
            #=======================================================================
            if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia') {
                if ($UBRPre -eq $UBR) {
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Warning 'The Update Build Revision did not change after Windows Updates'
                    Write-Warning 'There may have been an issue applying the Latest Cumulative Update if this was not expected'
                }
            }
            if (!($UBR)) {
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                $UBR = $((Get-Date).ToString('yyMMddhhmm'))
                Write-Warning 'Could not determine a UBR'
            }

            #=======================================================================
            # Remove Temporary Files
            #=======================================================================
            if (Test-Path "$WimTemp") {Remove-Item -Path "$WimTemp" -Force -Recurse | Out-Null}
            if (Test-Path "$MountDirectory") {Remove-Item -Path "$MountDirectory" -Force -Recurse | Out-Null}
            if (Test-Path "$MountWinRE") {Remove-Item -Path "$MountWinRE" -Force -Recurse | Out-Null}
            if (Test-Path "$MountWinPE") {Remove-Item -Path "$MountWinPE" -Force -Recurse | Out-Null}
            if (Test-Path "$MountWinSE") {Remove-Item -Path "$MountWinSE" -Force -Recurse | Out-Null}
            #=======================================================================
            # OSD-Export
            #=======================================================================
            Save-WindowsImageContentOS
            Save-VariablesOSD
            #=======================================================================
            # Create ISO
            #=======================================================================
            New-OSDBuilderISO -FullName "$WorkingPath"
            #=======================================================================
            # Complete Build
            #=======================================================================
            Stop-Transcript | Out-Null
        }
    }

    End {}
}