Public/New-OSBuild.ps1

<#
.SYNOPSIS
Creates a new OSBuild from an OSBuild Task

.DESCRIPTION
Creates a new OSBuild from an OSBuild Task created with New-OSBuildTask

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

.PARAMETER CreateISO
Creates an ISO of the OSBuilder Media

.PARAMETER DownloadUpdates
Automatically download the required updates if they are not present in the Content\Updates directory

.PARAMETER Execute
Execute the Build

.PARAMETER ByTaskName
Task Name to Execute

.PARAMETER DontUseNewestMedia
Use the OSMedia specified in the Task, not the Latest

.PARAMETER PromptBeforeDismount
Adds a 'Press Enter to Continue' prompt before the Install.wim is dismounted

.PARAMETER PromptBeforeDismountWinPE
Adds a 'Press Enter to Continue' prompt before the WinPE Wims are dismounted
#>

function New-OSBuild {
    [CmdletBinding(DefaultParameterSetName='Basic')]
    PARAM (
        [switch]$CreateISO,
        [switch]$DownloadUpdates,
        [switch]$Execute,
        [switch]$ShowMediaInfo,
        
        [Parameter(ParameterSetName='Advanced')]
        [string]$ByTaskName,
        
        [Parameter(ParameterSetName='Advanced')]
        [switch]$DontUseNewestMedia,

        [Parameter(ParameterSetName='Advanced')]
        [switch]$PromptBeforeDismount,

        [Parameter(ParameterSetName='Advanced')]
        [switch]$PromptBeforeDismountWinPE
    )

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

        #===================================================================================================
        Write-Verbose '19.1.1 Validate Administrator Rights'
        #===================================================================================================
        if (!([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
            Write-Warning 'OSBuilder: This function needs to be run as Administrator'
            Return
        }

        #===================================================================================================
        Write-Verbose '19.1.1 Initialize OSBuilder'
        #===================================================================================================
        Get-OSBuilder -CreatePaths -HideDetails

        #===================================================================================================
        Write-Verbose '19.1.1 Update Catalogs'
        #===================================================================================================
        if (!(Test-Path $CatalogLocal)) {$DownloadUpdates = $true}
        if ($DownloadUpdates.IsPresent) {Get-OSBUpdate -UpdateCatalogs -HideDetails}

        #===================================================================================================
        Write-Verbose '19.1.1 Gather All Updates'
        #===================================================================================================
        $CatalogsXmls = @()
        $ImportCatalog = @()
        $AllUpdates = @()

        $CatalogsXmls = Get-ChildItem "$OSBuilderContent\Updates" Cat*.xml -Recurse
        foreach ($CatalogsXml in $CatalogsXmls) {
            $ImportCatalog = Import-Clixml -Path "$($CatalogsXml.FullName)"
            $AllUpdates += $ImportCatalog
        }
        $AllUpdates = $AllUpdates | Select-Object -Property *
    }

    PROCESS {
        Write-Host '========================================================================================' -ForegroundColor DarkGray
        Write-Host "$($MyInvocation.MyCommand.Name) PROCESS" -ForegroundColor Green
        
        #===================================================================================================
        # OSBuild
        Write-Verbose '19.1.8 Get-OSBuildTask'
        #===================================================================================================
        if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {
            if ($ByTaskName) {
                $OSBuildTask = @()
                $OSBuildTask = Get-OSBuildTask | Where-Object {$_.TaskName -eq "$ByTaskName"}
            } else {
                $OSBuildTask = @()
                $OSBuildTask = Get-OSBuildTask | Out-GridView -PassThru -Title "OSBuild Tasks: Select one or more Tasks to execute and press OK (Cancel to Exit)"
            }
            if ($null -eq $OSBuildTask) {
                Write-Warning "OSBuild Task was not selected or found . . . Exiting!"
                Return
            }
        }

        #===================================================================================================
        # OSMedia
        Write-Verbose '19.1.3 Get-OSMedia'
        #===================================================================================================
        if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia') {
            if ($Name) {
                $OSMedia = foreach ($Item in $Name) {
                    Write-Verbose '========== Checking $Item'
                    $ObjectProperties = @{
                        Name = $Item
                    }
                    New-Object -TypeName PSObject -Property $ObjectProperties
                }
            } else {
                $OSMedia = @()
                $OSMedia = Get-OSMedia
                $OSMedia = $OSMedia | Where-Object {$_.MajorVersion -eq 10 -or $_.UBR -eq 7601.17514}
                if ($Repair.IsPresent) {
                    $OSMedia = $OSMedia | Where-Object {$_.Cumulative -eq 'Repair'}
                }
                $OSMedia = $OSMedia | Out-GridView -PassThru -Title "Select one or more OSMedia to Update (Cancel to Exit) and press OK"
            }
            if ($Repair.IsPresent) {$Execute = $true}
        }

        foreach ($Item in $OSBuildTask) {
            #===================================================================================================
            # OSBuild
            Write-Verbose '19.1.1 Read Task Contents'
            #===================================================================================================
            if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {
                (Get-Content "$($Item.FullName)").replace('WinPEAddDaRT', 'WinPEDaRT') | Set-Content "$($Item.FullName)"
                $Task = Get-Content "$($Item.FullName)" | ConvertFrom-Json
                $TaskType = $Task.TaskType
                $TaskName = $Task.TaskName
                $TaskVersion = $Task.TaskVersion
                $CustomName = $Task.CustomName

                $TaskOSMFamily = $Task.OSMFamily
                $TaskOSMGuid = $Task.OSMGuid
                $OSMediaName = $Task.Name
                $OSMediaPath = "$OSBuilderOSMedia\$OSMediaName"

                $EnableNetFX3 = $Task.EnableNetFX3
                $StartLayoutXML = $Task.StartLayoutXML
                $UnattendXML = $Task.UnattendXML
                $WinPEAutoExtraFiles = $Task.WinPEAutoExtraFiles
                $WinPEDaRT = $Task.WinPEDart
                
                $ExtraFiles = $Task.ExtraFiles
                $Scripts = $Task.Scripts
                $Drivers = $Task.Drivers

                $Packages = $Task.AddWindowsPackage
                $RemovePackage = $Task.RemoveWindowsPackage
                $FeaturesOnDemand = $Task.AddFeatureOnDemand
                $EnableFeature = $Task.EnableWindowsOptionalFeature
                $DisableFeature = $Task.DisableWindowsOptionalFeature
                $RemoveAppx = $Task.RemoveAppxProvisionedPackage
                $RemoveCapability = $Task.RemoveWindowsCapability

                $WinPEDrivers = $Task.WinPEDrivers
                $WinPEScriptsPE = $Task.WinPEScriptsPE
                $WinPEScriptsRE = $Task.WinPEScriptsRE
                $WinPEScriptsSE = $Task.WinPEScriptsSE
                $WinPEExtraFilesPE = $Task.WinPEExtraFilesPE
                $WinPEExtraFilesRE = $Task.WinPEExtraFilesRE
                $WinPEExtraFilesSE = $Task.WinPEExtraFilesSE
                $WinPEADKPE = $Task.WinPEADKPE
                $WinPEADKRE = $Task.WinPEADKRE
                $WinPEADKSE = $Task.WinPEADKSE
                
                $SetAllIntl = $Task.LangSetAllIntl
                $SetInputLocale = $Task.LangSetInputLocale
                $SetSKUIntlDefaults = $Task.LangSetSKUIntlDefaults
                $SetSetupUILang = $Task.LangSetSetupUILang
                $SetSysLocale = $Task.LangSetSysLocale
                $SetUILang = $Task.LangSetUILang
                $SetUILangFallback = $Task.LangSetUILangFallback
                $SetUserLocale = $Task.LangSetUserLocale
                $LanguageFeatures = $Task.LanguageFeature
                $LanguagePacks = $Task.LanguagePack
                $LanguageInterfacePacks = $Task.LanguageInterfacePack
                $LocalExperiencePacks = $Task.LocalExperiencePacks
            }
        
            #===================================================================================================
            # OSBuild
            Write-Verbose '19.1.1 OSBuild Task Information'
            #===================================================================================================
            if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Host "OSBuild Task Information" -ForegroundColor Green
                Write-Host "-TaskName: $TaskName"
                Write-Host "-TaskVersion: $TaskVersion"
                Write-Host "-TaskType: $TaskType"
                Write-Host "-OSMedia Name: $OSMediaName"
                Write-Host "-OSMedia Path: $OSMediaPath"
                Write-Host "-Custom Name: $CustomName"
                Write-Host "-Disable Feature:"
                if ($DisableFeature) {foreach ($item in $DisableFeature)            {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Drivers:"
                if ($Drivers) {foreach ($item in $Drivers)                          {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Enable Feature:"
                if ($EnableFeature) {foreach ($item in $EnableFeature)              {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Enable NetFx3: $EnableNetFX3"
                Write-Host "-Extra Files:"
                if ($ExtraFiles) {foreach ($item in $ExtraFiles)                    {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Features On Demand:"
                if ($FeaturesOnDemand) {foreach ($item in $FeaturesOnDemand)        {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Packages:"
                if ($Packages) {foreach ($item in $Packages)                        {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Remove Appx:"
                if ($RemoveAppx) {foreach ($item in $RemoveAppx)                    {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Remove Capability:"
                if ($RemoveCapability) {foreach ($item in $RemoveCapability)        {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Remove Packages:"
                if ($RemovePackage) {foreach ($item in $RemovePackage)              {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Scripts:"
                if ($Scripts) {foreach ($item in $Scripts)                          {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Start Layout: $StartLayoutXML"
                Write-Host "-Unattend: $UnattendXML"
                Write-Host "-All WinPE Auto ExtraFiles: $WinPEAutoExtraFiles"
                Write-Host "-All WinPE DaRT: $WinPEDaRT"
                Write-Host "-All WinPE Drivers:"
                if ($WinPEDrivers) {foreach ($item in $WinPEDrivers)                {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinPE ADK Packages:"
                if ($WinPEADKPE) {foreach ($item in $WinPEADKPE)                    {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinRE ADK Packages:"
                if ($WinPEADKRE) {foreach ($item in $WinPEADKRE)                    {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinSE ADK Packages:"
                if ($WinPEADKSE) {foreach ($item in $WinPEADKSE)                    {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinPE Extra Files:"
                if ($WinPEExtraFilesPE) {foreach ($item in $WinPEExtraFilesPE)      {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinRE Extra Files:"
                if ($WinPEExtraFilesRE) {foreach ($item in $WinPEExtraFilesRE)      {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinSE Extra Files:"
                if ($WinPEExtraFilesSE) {foreach ($item in $WinPEExtraFilesSE)      {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinPE Scripts:"
                if ($WinPEScriptsPE) {foreach ($item in $WinPEScriptsPE)            {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinRE Scripts:"
                if ($WinPEScriptsRE) {foreach ($item in $WinPEScriptsRE)            {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinSE Scripts:"
                if ($WinPEScriptsSE) {foreach ($item in $WinPEScriptsSE)            {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-SetAllIntl (Language): $SetAllIntl"
                Write-Host "-SetInputLocale (Language): $SetInputLocale"
                Write-Host "-SetSKUIntlDefaults (Language): $SetSKUIntlDefaults"
                Write-Host "-SetSetupUILang (Language): $SetSetupUILang"
                Write-Host "-SetSysLocale (Language): $SetSysLocale"
                Write-Host "-SetUILang (Language): $SetUILang"
                Write-Host "-SetUILangFallback (Language): $SetUILangFallback"
                Write-Host "-SetUserLocale (Language): $SetUserLocale"
                Write-Host "-Language Features:"
                if ($LanguageFeatures) {foreach ($item in $LanguageFeatures)        {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Language Interface Packs:"
                if ($LanguageInterfacePacks) {foreach ($item in $LanguageInterfacePacks) {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Language Packs:"
                if ($LanguagePacks) {foreach ($item in $LanguagePacks)              {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Local Experience Packs:"
                if ($LocalExperiencePacks) {foreach ($item in $LocalExperiencePacks){Write-Host $item -ForegroundColor DarkGray}}
            }
        
            #===================================================================================================
            # OSBuild
            Write-Verbose '19.1.1 Validate Proper TaskVersion'
            #===================================================================================================
            if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {
                if ([System.Version]$TaskVersion -lt [System.Version]"19.1.4.0") {
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Warning "OSBuilder Tasks need to be version 19.1.4.0 or newer"
                    Write-Warning "Recreate this Task using New-OSBuildTask or Repair-OSBuildTask"
                    Return
                }
            }

            #===================================================================================================
            # OSBuild
            Write-Verbose '19.1.8 Select Latest OSMedia'
            #===================================================================================================
            if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and (!($DontUseNewestMedia))) {
                $TaskOSMedia = Get-OSMedia | Where-Object {$_.OSMGuid -eq $TaskOSMGuid}
                if ($TaskOSMedia) {
                    $OSMediaName = $TaskOSMedia.Name
                    $OSMediaPath = $TaskOSMedia.FullName
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Task Source OSMedia" -ForegroundColor Green
                    Write-Host "-OSMedia Name: $OSMediaName"
                    Write-Host "-OSMedia Path: $OSMediaPath"
                    Write-Host "-OSMedia Family: $TaskOSMFamily"
                    Write-Host "-OSMedia Guid: $TaskOSMGuid"
                }
                $LatestOSMedia = Get-OSMedia | Where-Object {$_.OSMFamily -eq $TaskOSMFamily} | Sort-Object UBR | Select-Object -Last 1
                if ($LatestOSMedia) {
                    $OSMediaName = $LatestOSMedia.Name
                    $OSMediaPath = $LatestOSMedia.FullName
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Latest Source OSMedia" -ForegroundColor Green
                    Write-Host "-OSMedia Name: $OSMediaName"
                    Write-Host "-OSMedia Path: $OSMediaPath"
                    Write-Host "-OSMedia Family: $($LatestOSMedia.OSMFamily)"
                    Write-Host "-OSMedia Guid: $($LatestOSMedia.OSMGuid)"
                } else {
                    Write-Warning "Unable to find a matching OSMFamily $TaskOSMFamily"
                    Return
                }
            }
            
            #===================================================================================================
            # OSBuild
            Write-Verbose '19.1.20 Templates'
            #===================================================================================================
            if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and (Test-Path "$OSBuilderTemplates\Enabled")) {
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Host "OSBuild Templates" -ForegroundColor Green
                Write-Warning "Templates are under Development and may change at any time until finalized"
                $Templates = Get-ChildItem -Path "$OSBuilderTemplates\Enabled" *.json | ForEach-Object {Get-Content -Path $_.FullName | ConvertFrom-Json | Select-Object -Property *}

                foreach ($Task in $Templates) {
<# if ($Task.Scope -eq 'Global') {
                        Write-Host "Global Template: $($Task.TaskName)"
                    }
                    if ($Task.Scope -eq 'OSMFamily') {
                        if ($Task.OSMFamily -eq $TaskOSMFamily) {
                            Write-Host "OSMFamily Template: $($Task.TaskName)"
                        } else {
                            Write-Host "Skipping: $($Task.TaskName)" -ForegroundColor DarkGray
                            Continue
                        }
                    } else {
                        if ($Task.OSMFamily -eq $TaskOSMFamily) {
                            Write-Host "OSMFamily Template: $($Task.TaskName)"
                        }
                        else {
                            Write-Host "Skipping: $($Task.TaskName)" -ForegroundColor DarkGray
                            Continue
                        }
                    } #>


                    if ($Task.TaskName -like "*Global*") {
                        Write-Host "Global Template: $($Task.TaskName)"
                    } elseif ($Task.OSMFamily -eq $TaskOSMFamily) {
                        Write-Host "OSMFamily Template: $($Task.TaskName)"
                    } else {
                        Write-Host "Skipping: $($Task.TaskName)" -ForegroundColor DarkGray
                        Continue
                    }

                    if ($Task.EnableNetFX3) {$EnableNetFX3 = $Task.EnableNetFX3}
                    if ($Task.StartLayoutXML) {$StartLayoutXML = $Task.StartLayoutXML}
                    if ($Task.UnattendXML) {$UnattendXML = $Task.UnattendXML}
                    if ($Task.WinPEAutoExtraFiles) {$WinPEAutoExtraFiles = $Task.WinPEAutoExtraFiles}
                    if ($Task.WinPEDaRT) {$WinPEDaRT = $Task.WinPEDaRT}
                    
                    $ExtraFiles += @($Task.ExtraFiles | Where-Object {$_})
                    $Scripts += @($Task.Scripts | Where-Object {$_})
                    $Drivers += @($Task.Drivers | Where-Object {$_})
    
                    $Packages += @($Task.AddWindowsPackage | Where-Object {$_})
                    $RemovePackage += @($Task.RemoveWindowsPackage | Where-Object {$_})
                    $FeaturesOnDemand += @($Task.AddFeatureOnDemand | Where-Object {$_})
                    $EnableFeature += @($Task.EnableWindowsOptionalFeature | Where-Object {$_})
                    $DisableFeature += @($Task.DisableWindowsOptionalFeature | Where-Object {$_})
                    $RemoveAppx += @($Task.RemoveAppxProvisionedPackage | Where-Object {$_})
                    $RemoveCapability += @($Task.RemoveWindowsCapability | Where-Object {$_})
    
                    $WinPEDrivers += @($Task.WinPEDrivers | Where-Object {$_})
                    $WinPEScriptsPE += @($Task.WinPEScriptsPE | Where-Object {$_})
                    $WinPEScriptsRE += @($Task.WinPEScriptsRE | Where-Object {$_})
                    $WinPEScriptsSE += @($Task.WinPEScriptsSE | Where-Object {$_})
                    $WinPEExtraFilesPE += @($Task.WinPEExtraFilesPE | Where-Object {$_})
                    $WinPEExtraFilesRE += @($Task.WinPEExtraFilesRE | Where-Object {$_})
                    $WinPEExtraFilesSE += @($Task.WinPEExtraFilesSE | Where-Object {$_})
                    $WinPEADKPE += @($Task.WinPEADKPE | Where-Object {$_})
                    $WinPEADKRE += @($Task.WinPEADKRE | Where-Object {$_})
                    $WinPEADKSE += @($Task.WinPEADKSE | Where-Object {$_})
                    
                    #$SetAllIntl = @($Task.LangSetAllIntl | Where-Object {$_})
                    #$SetInputLocale = @($Task.LangSetInputLocale | Where-Object {$_})
                    #$SetSKUIntlDefaults = @($Task.LangSetSKUIntlDefaults | Where-Object {$_})
                    #$SetSetupUILang = @($Task.LangSetSetupUILang | Where-Object {$_})
                    #$SetSysLocale = @($Task.LangSetSysLocale | Where-Object {$_})
                    #$SetUILang = @($Task.LangSetUILang | Where-Object {$_})
                    #$SetUILangFallback = @($Task.LangSetUILangFallback | Where-Object {$_})
                    #$SetUserLocale = @($Task.LangSetUserLocale | Where-Object {$_})
                    #$LanguageFeatures = @($Task.LanguageFeature | Where-Object {$_})
                    #$LanguagePacks = @($Task.LanguagePack | Where-Object {$_})
                    #$LanguageInterfacePacks = @($Task.LanguageInterfacePack | Where-Object {$_})
                    #$LocalExperiencePacks = @($Task.LocalExperiencePacks | Where-Object {$_})
                }
            }
        
            #===================================================================================================
            # OSBuild
            Write-Verbose '19.1.1 OSBuild Task Information'
            #===================================================================================================
            if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Host "OSBuild Task Information with Templates" -ForegroundColor Green
                Write-Host "-TaskName: $TaskName"
                Write-Host "-TaskVersion: $TaskVersion"
                Write-Host "-TaskType: $TaskType"
                Write-Host "-OSMedia Name: $OSMediaName"
                Write-Host "-OSMedia Path: $OSMediaPath"
                Write-Host "-Custom Name: $CustomName"
                Write-Host "-Disable Feature:"
                if ($DisableFeature) {foreach ($item in $DisableFeature)            {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Drivers:"
                if ($Drivers) {foreach ($item in $Drivers)                          {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Enable Feature:"
                if ($EnableFeature) {foreach ($item in $EnableFeature)              {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Enable NetFx3: $EnableNetFX3"
                Write-Host "-Extra Files:"
                if ($ExtraFiles) {foreach ($item in $ExtraFiles)                    {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Features On Demand:"
                if ($FeaturesOnDemand) {foreach ($item in $FeaturesOnDemand)        {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Packages:"
                if ($Packages) {foreach ($item in $Packages)                        {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Remove Appx:"
                if ($RemoveAppx) {foreach ($item in $RemoveAppx)                    {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Remove Capability:"
                if ($RemoveCapability) {foreach ($item in $RemoveCapability)        {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Remove Packages:"
                if ($RemovePackage) {foreach ($item in $RemovePackage)              {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Scripts:"
                if ($Scripts) {foreach ($item in $Scripts)                          {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Start Layout: $StartLayoutXML"
                Write-Host "-Unattend: $UnattendXML"
                Write-Host "-WinPE Auto ExtraFiles: $WinPEAutoExtraFiles"
                Write-Host "-WinPE DaRT: $WinPEDaRT"
                Write-Host "-WinPE Drivers:"
                if ($WinPEDrivers) {foreach ($item in $WinPEDrivers)                {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinPE ADK Packages:"
                if ($WinPEADKPE) {foreach ($item in $WinPEADKPE)                    {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinRE ADK Packages:"
                if ($WinPEADKRE) {foreach ($item in $WinPEADKRE)                    {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinSE ADK Packages:"
                if ($WinPEADKSE) {foreach ($item in $WinPEADKSE)                    {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinPE Extra Files:"
                if ($WinPEExtraFilesPE) {foreach ($item in $WinPEExtraFilesPE)      {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinRE Extra Files:"
                if ($WinPEExtraFilesRE) {foreach ($item in $WinPEExtraFilesRE)      {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinSE Extra Files:"
                if ($WinPEExtraFilesSE) {foreach ($item in $WinPEExtraFilesSE)      {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinPE Scripts:"
                if ($WinPEScriptsPE) {foreach ($item in $WinPEScriptsPE)            {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinRE Scripts:"
                if ($WinPEScriptsRE) {foreach ($item in $WinPEScriptsRE)            {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-WinSE Scripts:"
                if ($WinPEScriptsSE) {foreach ($item in $WinPEScriptsSE)            {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-SetAllIntl (Language): $SetAllIntl"
                Write-Host "-SetInputLocale (Language): $SetInputLocale"
                Write-Host "-SetSKUIntlDefaults (Language): $SetSKUIntlDefaults"
                Write-Host "-SetSetupUILang (Language): $SetSetupUILang"
                Write-Host "-SetSysLocale (Language): $SetSysLocale"
                Write-Host "-SetUILang (Language): $SetUILang"
                Write-Host "-SetUILangFallback (Language): $SetUILangFallback"
                Write-Host "-SetUserLocale (Language): $SetUserLocale"
                Write-Host "-Language Features:"
                if ($LanguageFeatures) {foreach ($item in $LanguageFeatures)        {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Language Interface Packs:"
                if ($LanguageInterfacePacks) {foreach ($item in $LanguageInterfacePacks) {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Language Packs:"
                if ($LanguagePacks) {foreach ($item in $LanguagePacks)              {Write-Host $item -ForegroundColor DarkGray}}
                Write-Host "-Local Experience Packs:"
                if ($LocalExperiencePacks) {foreach ($item in $LocalExperiencePacks){Write-Host $item -ForegroundColor DarkGray}}
            }

            #===================================================================================================
            # OSBuild
            Write-Verbose '19.1.1 Set Proper Paths'
            #===================================================================================================
            if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia') {
                $OSMediaPath = "$OSBuilderOSMedia\$($Item.Name)"
            }
            $OSImagePath = "$OSMediaPath\OS\sources\install.wim"

            if (!(Test-Path "$OSMediaPath\WindowsImage.txt")) {
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                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
            }

            #===================================================================================================
            Write-Verbose '19.1.1 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)
            $OSMajorVersion =       $($WindowsImage.MajorVersion)
            $OSBuild =              $($WindowsImage.Build)
            $OSVersion =            $($WindowsImage.Version)
            $OSSPBuild =            $($WindowsImage.SPBuild)
            $OSSPLevel =            $($WindowsImage.SPLevel)
            $OSImageBootable =      $($WindowsImage.ImageBootable)
            $OSWIMBoot =            $($WindowsImage.WIMBoot)
            $OSCreatedTime =        $($WindowsImage.CreatedTime)
            $OSModifiedTime =       $($WindowsImage.ModifiedTime)

            #===================================================================================================
            Write-Verbose '19.1.1 Source OSMedia Windows Image Information'
            #===================================================================================================
            Write-Host '========================================================================================' -ForegroundColor DarkGray
            Write-Host "Source OSMedia Windows Image Information" -ForegroundColor Green
            Write-Host "-OSMedia Path: $OSMediaPath" -ForegroundColor Yellow
            Write-Host "-Image File: $OSImagePath"
            Write-Host "-Image Index: $OSImageIndex"
            Write-Host "-Name: $OSImageName"
            Write-Host "-Description: $OSImageDescription"
            Write-Host "-Architecture: $OSArchitecture"
            Write-Host "-Edition: $OSEditionID"
            Write-Host "-Type: $OSInstallationType"
            Write-Host "-Languages: $OSLanguages"
            Write-Host "-Major Version: $OSMajorVersion"
            Write-Host "-Build: $OSBuild"
            Write-Host "-Version: $OSVersion"
            Write-Host "-SPBuild: $OSSPBuild"
            Write-Host "-SPLevel: $OSSPLevel"
            Write-Host "-Bootable: $OSImageBootable"
            Write-Host "-WimBoot: $OSWIMBoot"
            Write-Host "-Created Time: $OSCreatedTime"
            Write-Host "-Modified Time: $OSModifiedTime"

            #===================================================================================================
            Write-Verbose '19.1.1 Validate Registry CurrentVersion.xml'
            #===================================================================================================
            if (Test-Path "$OSMediaPath\info\xml\CurrentVersion.xml") {
                $RegCurrentVersion = Import-Clixml -Path "$OSMediaPath\info\xml\CurrentVersion.xml"
                $OSVersionNumber = $($RegCurrentVersion.ReleaseId)
                if ($OSVersionNumber -gt 1809) {
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Warning "OSBuilder does not currently support this version of Windows ... Check for an updated version"
                }
            }

            #===================================================================================================
            Write-Verbose '19.1.1 Set OSVersionNumber'
            #===================================================================================================
            if ($null -eq $OSVersionNumber) {
                if ($OSBuild -eq 7601) {$OSVersionNumber = 7601}
                if ($OSBuild -eq 10240) {$OSVersionNumber = 1507}
                if ($OSBuild -eq 14393) {$OSVersionNumber = 1607}
                if ($OSBuild -eq 15063) {$OSVersionNumber = 1703}
                if ($OSBuild -eq 16299) {$OSVersionNumber = 1709}
                if ($OSBuild -eq 17134) {$OSVersionNumber = 1803}
                if ($OSBuild -eq 17763) {$OSVersionNumber = 1809}
            }

            #===================================================================================================
            Write-Verbose '19.1.1 WorkingName and WorkingPath'
            #===================================================================================================
            if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia' -and $Repair.IsPresent) {
                $WorkingName = $($Item.Name)
                $WorkingPath = $OSMediaPath
            } elseif ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {
                $WorkingName = "build$((Get-Date).ToString('mmss'))"
                $WorkingPath = "$OSBuilderOSBuilds\$WorkingName"
            } else {
                $WorkingName = "build$((Get-Date).ToString('mmss'))"
                $WorkingPath = "$OSBuilderOSMedia\$WorkingName"
            }

            if (!($Repair.IsPresent)) {
                #===================================================================================================
                Write-Verbose '19.1.1 Remove Existing OSMedia'
                #===================================================================================================
                if (Test-Path $WorkingPath) {
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Warning "$WorkingPath will be replaced!"
                }

                #===================================================================================================
                # OSBuild
                Write-Verbose '19.1.11 Disable Windows 7 Updates'
                #===================================================================================================
                if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and $OSVersionNumber -eq 7601) {
                    $AllUpdates = @()
                }
                #===================================================================================================
                Write-Verbose '19.1.1 Setup Updates'
                #===================================================================================================
                $UpdateCatSetup = @()
                $UpdateCatSetup = $AllUpdates | Where-Object {$_.Category -eq 'Setup'}
                $UpdateCatSetup = $UpdateCatSetup | Where-Object {$_.KBTitle -like "*$OSVersionNumber*"}
                $UpdateCatSetup = $UpdateCatSetup | Where-Object {$_.KBTitle -like "*$OSArchitecture*"}
                if ($OSInstallationType -like "*Server*") {
                    $UpdateCatSetup = $UpdateCatSetup | Where-Object {$_.KBTitle -like "*Server*"}
                } else {
                    $UpdateCatSetup = $UpdateCatSetup | Where-Object {$_.KBTitle -notlike "*Server*"}
                }
                $UpdateCatSetup = $UpdateCatSetup | Sort-Object -Property DatePosted

                #===================================================================================================
                Write-Verbose '19.1.1 Servicing Stack Updates'
                #===================================================================================================
                $UpdateCatServicing = @()
                $UpdateCatServicing = $AllUpdates | Where-Object {$_.Category -eq 'Servicing'}
                $UpdateCatServicing = $UpdateCatServicing | Where-Object {$_.KBTitle -like "*$OSVersionNumber*"}
                $UpdateCatServicing = $UpdateCatServicing | Where-Object {$_.KBTitle -like "*$OSArchitecture*"}
                if ($OSInstallationType -like "*Server*") {
                    $UpdateCatServicing = $UpdateCatServicing | Where-Object {$_.KBTitle -like "*Server*"}
                } else {
                    $UpdateCatServicing = $UpdateCatServicing | Where-Object {$_.KBTitle -notlike "*Server*"}
                }
                $UpdateCatServicing = $UpdateCatServicing | Sort-Object -Property DatePosted

                #===================================================================================================
                Write-Verbose '19.1.1 Latest Cumulative Updates'
                #===================================================================================================
                $UpdateCatCumulative = @()
                $UpdateCatCumulative = $AllUpdates | Where-Object {$_.Category -eq 'Cumulative'}
                $UpdateCatCumulative = $UpdateCatCumulative | Where-Object {$_.KBTitle -like "*$OSVersionNumber*"}
                $UpdateCatCumulative = $UpdateCatCumulative | Where-Object {$_.KBTitle -like "*$OSArchitecture*"}
                if ($OSInstallationType -like "*Server*") {
                    $UpdateCatCumulative = $UpdateCatCumulative | Where-Object {$_.KBTitle -like "*Server*"}
                } else {
                    $UpdateCatCumulative = $UpdateCatCumulative | Where-Object {$_.KBTitle -notlike "*Server*"}
                }
                $UpdateCatCumulative = $UpdateCatCumulative | Sort-Object -Property DatePosted | Select-Object -Last 1
                #$UpdateCatCumulative = $UpdateCatCumulative | Sort-Object -Property DatePosted

                #===================================================================================================
                Write-Verbose '19.1.1 DotNet Framework Updates'
                #===================================================================================================
                $UpdateCatDotNet = @()
                $UpdateCatDotNet = $AllUpdates | Where-Object {$_.Category -eq 'DotNet'}
                $UpdateCatDotNet = $UpdateCatDotNet | Where-Object {$_.KBTitle -like "*$OSVersionNumber*"}
                $UpdateCatDotNet = $UpdateCatDotNet | Where-Object {$_.KBTitle -like "*$OSArchitecture*"}
                if ($OSInstallationType -like "*Server*") {
                    $UpdateCatDotNet = $UpdateCatDotNet | Where-Object {$_.KBTitle -like "*Server*"}
                } else {
                    $UpdateCatDotNet = $UpdateCatDotNet | Where-Object {$_.KBTitle -notlike "*Server*"}
                }
                $UpdateCatDotNet = $UpdateCatDotNet | Sort-Object -Property DatePosted | Select-Object -Last 1

                #===================================================================================================
                Write-Verbose '19.1.1 Adobe Flash Security Updates'
                #===================================================================================================
                $UpdateCatAdobe = @()
                $UpdateCatAdobe = $AllUpdates | Where-Object {$_.Category -eq 'Adobe'}
                $UpdateCatAdobe = $UpdateCatAdobe | Where-Object {$_.KBTitle -like "*$OSVersionNumber*"}
                $UpdateCatAdobe = $UpdateCatAdobe | Where-Object {$_.KBTitle -like "*$OSArchitecture*"}
                if ($OSInstallationType -like "*Server*") {
                    $UpdateCatAdobe = $UpdateCatAdobe | Where-Object {$_.KBTitle -like "*Server*"}
                } else {
                    $UpdateCatAdobe = $UpdateCatAdobe | Where-Object {$_.KBTitle -notlike "*Server*"}
                }
                $UpdateCatAdobe = $UpdateCatAdobe | Sort-Object -Property DatePosted | Select-Object -Last 1

                #===================================================================================================
                Write-Verbose '19.1.1 Component Updates'
                #===================================================================================================
                $UpdateCatComponent = @()
                $UpdateCatComponent = $AllUpdates | Where-Object {$_.Category -eq 'Component'}
                $UpdateCatComponent = $UpdateCatComponent | Where-Object {$_.KBTitle -like "*$OSVersionNumber*"}
                $UpdateCatComponent = $UpdateCatComponent | Where-Object {$_.KBTitle -like "*$OSArchitecture*"}
                if ($OSInstallationType -like "*Server*") {
                    $UpdateCatComponent = $UpdateCatComponent | Where-Object {$_.KBTitle -like "*Server*"}
                } else {
                    $UpdateCatComponent = $UpdateCatComponent | Where-Object {$_.KBTitle -notlike "*Server*"}
                }
                $UpdateCatComponent = $UpdateCatComponent | Sort-Object -Property DatePosted

                #===================================================================================================
                Write-Verbose '19.1.1 Windows 7'
                #===================================================================================================
                $CatalogWindows7 = @()
                $CatalogWindows7WinPE = @()
                if ($OSVersion -like "6.1.7601.*" -and $OSInstallationType -eq 'Client') {
                    $CatalogWindows7 = $AllUpdates | Where-Object {$_.Category -like "*Windows 7*"}
                    $CatalogWindows7 = $CatalogWindows7 | Where-Object {$_.KBTitle -like "*$OSArchitecture*"}
                    $CatalogWindows7 = $CatalogWindows7 | Sort-Object -Property DatePosted

                    $CatalogWindows7 = $CatalogWindows7 | Sort-Object -Property DatePosted

                    $CatalogWindows7WinPE = $CatalogWindows7 | Where-Object {$_.Severity -eq 'WinPE'}
                }

                #===================================================================================================
                Write-Verbose '19.1.1 Update Validation'
                #===================================================================================================
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Host "Operating System Updates" -ForegroundColor Green

                foreach ($Update in $UpdateCatSetup) {
                    $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                    if (!(Test-Path "$OSBuilderContent\Updates\*\$($Update.KBTitle)\$($Update.FileName)")) {
                        if ($DownloadUpdates.IsPresent) {
                            Write-Warning "Missing $($Update.KBTitle) ... Downloading"
                            Get-OSBUpdate -FilterKBTitle "$($Update.KBTitle)" -Download -HideDetails
                        } else {
                            Write-Warning "Missing $($Update.KBTitle) ... Execution will be Disabled"
                            $Execute = $false
                        }
                    }
                }

                foreach ($Update in $UpdateCatServicing) {
                    $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                    if (!(Test-Path "$OSBuilderContent\Updates\*\$($Update.KBTitle)\$($Update.FileName)")) {
                        if ($DownloadUpdates.IsPresent) {
                            Write-Warning "Missing $($Update.KBTitle) ... Downloading"
                            Get-OSBUpdate -FilterKBTitle "$($Update.KBTitle)" -Download -HideDetails
                        } else {
                            Write-Warning "Missing $($Update.KBTitle) ... Execution will be Disabled"
                            $Execute = $false
                        }
                    }
                }

                foreach ($Update in $UpdateCatCumulative) {
                    $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                    if (!(Test-Path "$OSBuilderContent\Updates\*\$($Update.KBTitle)\$($Update.FileName)")) {
                        if ($DownloadUpdates.IsPresent) {
                            Write-Warning "Missing $($Update.KBTitle) ... Downloading"
                            Get-OSBUpdate -FilterKBTitle "$($Update.KBTitle)" -Download -HideDetails
                        } else {
                            Write-Warning "Missing $($Update.KBTitle) ... Execution will be Disabled"
                            $Execute = $false
                        }
                    }
                }

                foreach ($Update in $UpdateCatDotNet) {
                    $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                    if (!(Test-Path "$OSBuilderContent\Updates\*\$($Update.KBTitle)\$($Update.FileName)")) {
                        if ($DownloadUpdates.IsPresent) {
                            Write-Warning "Missing $($Update.KBTitle) ... Downloading"
                            Get-OSBUpdate -FilterKBTitle "$($Update.KBTitle)" -Download -HideDetails
                        } else {
                            Write-Warning "Missing $($Update.KBTitle) ... Execution will be Disabled"
                            $Execute = $false
                        }
                    }
                }

                foreach ($Update in $UpdateCatAdobe) {
                    $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                    if (!(Test-Path "$OSBuilderContent\Updates\*\$($Update.KBTitle)\$($Update.FileName)")) {
                        if ($DownloadUpdates.IsPresent) {
                            Write-Warning "Missing $($Update.KBTitle) ... Downloading"
                            Get-OSBUpdate -FilterKBTitle "$($Update.KBTitle)" -Download -HideDetails
                        } else {
                            Write-Warning "Missing $($Update.KBTitle) ... Execution will be Disabled"
                            $Execute = $false
                        }
                    }
                }

                foreach ($Update in $UpdateCatComponent) {
                    $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                    if (!(Test-Path "$OSBuilderContent\Updates\*\$($Update.KBTitle)\$($Update.FileName)")) {
                        if ($DownloadUpdates.IsPresent) {
                            Write-Warning "Missing $($Update.KBTitle) ... Downloading"
                            Get-OSBUpdate -FilterKBTitle "$($Update.KBTitle)" -Download -HideDetails
                        } else {
                            Write-Warning "Missing $($Update.KBTitle) ... Execution will be Disabled"
                            $Execute = $false
                        }
                    }
                }

                if ($OSVersion -like "6.1.7601.*") {
                    foreach ($Update in $CatalogWindows7) {
                        $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                        if (!(Test-Path "$OSBuilderContent\Updates\*\$($Update.KBTitle)\$($Update.FileName)")) {
                            if ($DownloadUpdates.IsPresent) {
                                Write-Warning "Missing $($Update.KBTitle) ... Downloading"
                                Get-OSBUpdate -FilterKBTitle "$($Update.KBTitle)" -Download -HideDetails
                            } else {
                                Write-Warning "Missing $($Update.KBTitle) ... Execution will be Disabled"
                                $Execute = $false
                            }
                        }
                    }
                }
            }

            #===================================================================================================
            Write-Verbose '19.1.1 Execute'
            #===================================================================================================
            if ($Execute.IsPresent) {

                #===================================================================================================
                Write-Verbose '19.1.1 Remove Existing WorkingPath'
                #===================================================================================================
                if (!($Repair.IsPresent)) {
                    if (Test-Path $WorkingPath) {
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Remove-Item -Path "$WorkingPath" -Force -Recurse
                    }
                }

                #===================================================================================================
                Write-Verbose '19.1.1 Set Working Directories'
                #===================================================================================================
                $Info = Join-Path $WorkingPath 'info'
                if (!(Test-Path "$Info"))           {New-Item "$Info" -ItemType Directory -Force | Out-Null}
                if (!(Test-Path "$Info\json"))      {New-Item "$Info\json" -ItemType Directory -Force | Out-Null}
                if (!(Test-Path "$Info\logs"))      {New-Item "$Info\logs" -ItemType Directory -Force | Out-Null}
                if (!(Test-Path "$Info\xml"))       {New-Item "$Info\xml" -ItemType Directory -Force | Out-Null}

                $OS = Join-Path $WorkingPath 'OS'
                if (!(Test-Path "$OS"))             {New-Item "$OS" -ItemType Directory -Force | Out-Null}

                $WinPE = Join-Path $WorkingPath 'WinPE'
                if (!(Test-Path "$WinPE"))          {New-Item "$WinPE" -ItemType Directory -Force | Out-Null}

                $PEInfo = Join-Path $WinPE 'info'
                if (!(Test-Path "$PEInfo"))         {New-Item "$PEInfo" -ItemType Directory -Force | Out-Null}
                if (!(Test-Path "$PEInfo\json"))    {New-Item "$PEInfo\json" -ItemType Directory -Force | Out-Null}
                if (!(Test-Path "$PEInfo\logs"))    {New-Item "$PEInfo\logs" -ItemType Directory -Force | Out-Null}
                if (!(Test-Path "$PEInfo\xml"))     {New-Item "$PEInfo\xml" -ItemType Directory -Force | Out-Null}

                #===================================================================================================
                Write-Verbose '19.1.1 Set Logs'
                #===================================================================================================
                $Logs = Join-Path $Info 'logs'
                $PELogs = Join-Path $PEInfo 'logs'

                #===================================================================================================
                Write-Verbose '19.1.1 Set WimTemp'
                #===================================================================================================
                $WimTemp = Join-Path $WorkingPath "WimTemp"
                if (!(Test-Path "$WimTemp"))        {New-Item "$WimTemp" -ItemType Directory -Force | Out-Null}

                #===================================================================================================
                Write-Verbose '19.1.1 Start Transcript'
                #===================================================================================================
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                $ScriptName = $($MyInvocation.MyCommand.Name)
                $LogName = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$ScriptName.log"
                Start-Transcript -Path (Join-Path "$Info\logs" $LogName)

                #===================================================================================================
                Write-Verbose '19.1.1 Working Information'
                #===================================================================================================
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Host "Working Information" -ForegroundColor Green
                Write-Host "-WorkingName: $WorkingName" -ForegroundColor Yellow
                Write-Host "-WorkingPath: $WorkingPath" -ForegroundColor Yellow
                Write-Host "-OS: $OS"
                Write-Host "-WinPE: $WinPE"
                Write-Host "-Info: $Info"
                Write-Host "-Logs: $Info\logs"

                #===================================================================================================
                Write-Verbose '19.1.1 Create Mount Directories'
                #===================================================================================================
                $MountDirectory = Join-Path $OSBuilderContent\Mount "os$((Get-Date).ToString('mmss'))"
                if ( ! (Test-Path "$MountDirectory")) {New-Item "$MountDirectory" -ItemType Directory -Force | Out-Null}
                $MountWinPE = Join-Path $OSBuilderContent\Mount "winpe$((Get-Date).ToString('mmss'))"
                if ( ! (Test-Path "$MountWinPE")) {New-Item "$MountWinPE" -ItemType Directory -Force | Out-Null}
                $MountWinSE = Join-Path $OSBuilderContent\Mount "setup$((Get-Date).ToString('mmss'))"
                if ( ! (Test-Path "$MountWinSE")) {New-Item "$MountWinSE" -ItemType Directory -Force | Out-Null}
                $MountWinRE = Join-Path $OSBuilderContent\Mount "winre$((Get-Date).ToString('mmss'))"
                if ( ! (Test-Path "$MountWinRE")) {New-Item "$MountWinRE" -ItemType Directory -Force | Out-Null}

                #===================================================================================================
                if ($Repair.IsPresent) {
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Repair: Operating System at $WorkingPath" -ForegroundColor Green
                    Copy-Item -Path "$OSMediaPath\WinPE\*.wim" -Destination "$WimTemp" -Exclude boot.wim -Force | Out-Null
                    if (Test-Path "$WorkingPath\OS\sources\install.wim") {
                        Copy-Item -Path "$WorkingPath\OS\sources\install.wim" -Destination "$WimTemp\install.wim" -Force | Out-Null
                        Remove-Item -Path "$WorkingPath\OS\Sources\install.wim" -Force | Out-Null
                    }
                    if (Test-Path "$WorkingPath\OS\Sources\boot.wim") {Remove-Item -Path "$WorkingPath\OS\Sources\boot.wim" -Force | Out-Null}
                    if (Test-Path "$WorkingPath\WinPE\boot.wim") {Remove-Item -Path "$WorkingPath\WinPE\boot.wim" -Force | Out-Null}
                    if (Test-Path "$WorkingPath\WinPE\winpe.wim") {Remove-Item -Path "$WorkingPath\WinPE\winpe.wim" -Force | Out-Null}
                    if (Test-Path "$WorkingPath\WinPE\winre.wim") {Remove-Item -Path "$WorkingPath\WinPE\winre.wim" -Force | Out-Null}
                    if (Test-Path "$WorkingPath\WinPE\winse.wim") {Remove-Item -Path "$WorkingPath\WinPE\winse.wim" -Force | Out-Null}
                }
                
                #===================================================================================================
                Write-Verbose '19.1.1 Media: Copy Operating System'
                #===================================================================================================
                if (!($Repair.IsPresent)) {
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Media: Copy Operating System to $WorkingPath" -ForegroundColor Green
                    Copy-Item -Path "$OSMediaPath\*" -Destination "$WorkingPath" -Exclude ('*.wim','*.iso') -Recurse -Force | Out-Null
                    if (Test-Path "$WorkingPath\ISO") {Remove-Item -Path "$WorkingPath\ISO" -Force -Recurse | Out-Null}
                    Copy-Item -Path "$OSMediaPath\OS\sources\install.wim" -Destination "$WimTemp\install.wim" -Force | Out-Null
                    Copy-Item -Path "$OSMediaPath\WinPE\*.wim" -Destination "$WimTemp" -Exclude boot.wim -Force | Out-Null
                }

                #===================================================================================================
                Write-Verbose '19.1.1 Media: Setup Update'
                #===================================================================================================
                if (!($Repair.IsPresent)) {
                    #Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Media: Setup Update" -ForegroundColor Green
                    if (!($null -eq $UpdateCatSetup)) {
                        foreach ($Update in $UpdateCatSetup) {
                            $UpdateCatSetup = $(Get-ChildItem -Path $OSBuilderContent\Updates -File -Recurse | Where-Object {$_.Name -eq $($Update.FileName)}).FullName
                            $UpdateCatSetup
                            if (Test-Path "$UpdateCatSetup") {
                                expand.exe "$UpdateCatSetup" -F:*.* "$OS\Sources"
                            } else {
                                Write-Warning "Not Found: $UpdateCatSetup ... Skipping Update"
                            }
                        }
                    }
                }

                #===================================================================================================
                Write-Verbose '19.1.1 Mount WinPE'
                #===================================================================================================
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                Mount-OSBWinPE -OSMediaPath "$WorkingPath" -MountWinPE "$MountWinPE" -MountWinRE "$MountWinRE" -MountWinSE "$MountWinSE"

                #===================================================================================================
                Write-Verbose '19.1.1 WinPE: Servicing Stack Update'
                #===================================================================================================
                if (!($Repair.IsPresent)) {
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: (SSU) Servicing Stack Update" -ForegroundColor Green

                    if (!($null -eq $UpdateCatServicing)) {
                        foreach ($Update in $UpdateCatServicing) {
                            $UpdateSSU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                            if (Test-Path "$UpdateSSU") {
                                Write-Host "$UpdateSSU" -ForegroundColor DarkGray

                                if (Get-WindowsPackage -Path "$MountWinPE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {
                                    Write-Warning "WinPE.wim KB$($Update.KBNumber) is already installed"
                                } else {
                                    $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateServicing-KB$($Update.KBNumber)-WinPE.log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountWinPE" -PackagePath "$UpdateSSU" -LogPath "$CurrentLog" | Out-Null
                                }

                                if (Get-WindowsPackage -Path "$MountWinRE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {
                                    Write-Warning "WinRE.wim KB$($Update.KBNumber) is already installed"
                                } else {
                                    $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateServicing-KB$($Update.KBNumber)-WinRE.log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountWinRE" -PackagePath "$UpdateSSU" -LogPath "$CurrentLog" | Out-Null
                                }

                                if (Get-WindowsPackage -Path "$MountWinSE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {
                                    Write-Warning "WinSE.wim KB$($Update.KBNumber) is already installed"
                                } else {
                                    $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateServicing-KB$($Update.KBNumber)-WinSE.log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountWinSE" -PackagePath "$UpdateSSU" -LogPath "$CurrentLog" | Out-Null
                                }
                            } else {
                                Write-Warning "Not Found: $UpdateSSU ... Skipping Update"
                            }
                        }
                    }
                }
                
                if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {
                    #===================================================================================================
                    Write-Verbose '19.1.1 WinPE WIM ADK Optional Components'
                    # OSBuild Only
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: WinPE.wim ADK Optional Components" -ForegroundColor Green
                    if ([string]::IsNullOrEmpty($WinPEADKPE) -or [string]::IsNullOrWhiteSpace($WinPEADKPE)) {
                        # Do Nothing
                    } else {
                        foreach ($PackagePath in $WinPEADKPE) {
                            if ($PackagePath -like "*WinPE-NetFx*") {
                                Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray
                                Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinPE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-WinPE.log" | Out-Null
                            }
                        }
                        $WinPEADKPE = $WinPEADKPE | Where-Object {$_.Name -notlike "*WinPE-NetFx*"}
                        foreach ($PackagePath in $WinPEADKPE) {
                            if ($PackagePath -like "*WinPE-PowerShell*") {
                                Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray
                                Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinPE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-WinPE.log" | Out-Null
                            }
                        }
                        $WinPEADKPE = $WinPEADKPE | Where-Object {$_.Name -notlike "*WinPE-PowerShell*"}
                        foreach ($PackagePath in $WinPEADKPE) {
                            Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray
                            if ($OSMajorVersion -eq 6) {
                                dism /Image:"$MountWinPE" /Add-Package /PackagePath:"$OSBuilderContent\$PackagePath" /LogPath:"$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DISM-Add-WindowsPackage-WinPE.log"
                            } else {
                                Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinPE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-WinPE.log" | Out-Null
                            }
                        }
                    }
                    #===================================================================================================
                    Write-Verbose '19.1.1 WinRE WIM ADK Optional Components'
                    # OSBuild Only
                    #===================================================================================================
                    #Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: WinRE.wim ADK Optional Components" -ForegroundColor Green
                    if ([string]::IsNullOrEmpty($WinPEADKRE) -or [string]::IsNullOrWhiteSpace($WinPEADKRE)) {
                        # Do Nothing
                    } else {
                        foreach ($PackagePath in $WinPEADKRE) {
                            if ($PackagePath -like "*WinPE-NetFx*") {
                                Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray
                                Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinRE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-WinRE.log" | Out-Null
                            }
                        }
                        $WinPEADKRE = $WinPEADKRE | Where-Object {$_.Name -notlike "*WinPE-NetFx*"}
                        foreach ($PackagePath in $WinPEADKRE) {
                            if ($PackagePath -like "*WinPE-PowerShell*") {
                                Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray
                                Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinRE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-WinRE.log" | Out-Null
                            }
                        }
                        $WinPEADKRE = $WinPEADKRE | Where-Object {$_.Name -notlike "*WinPE-PowerShell*"}
                        foreach ($PackagePath in $WinPEADKRE) {
                            Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray
                            if ($OSMajorVersion -eq 6) {
                                dism /Image:"$MountWinRE" /Add-Package /PackagePath:"$OSBuilderContent\$PackagePath" /LogPath:"$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DISM-Add-WindowsPackage-WinRE.log"
                            } else {
                                Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinRE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-WinRE.log" | Out-Null
                            }
                        }
                    }
                    #===================================================================================================
                    Write-Verbose '19.1.1 Setup WIM ADK Optional Components'
                    # OSBuild Only
                    #===================================================================================================
                    #Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: WinSE.wim ADK Optional Components" -ForegroundColor Green
                    if ([string]::IsNullOrEmpty($WinPEADKSE) -or [string]::IsNullOrWhiteSpace($WinPEADKSE)) {
                        # Do Nothing
                    } else {
                        foreach ($PackagePath in $WinPEADKSE) {
                            if ($PackagePath -like "*WinPE-NetFx*") {
                                Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray
                                Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinSE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-WinSE.log" | Out-Null
                            }
                        }
                        $WinPEADKSE = $WinPEADKSE | Where-Object {$_.Name -notlike "*WinPE-NetFx*"}
                        foreach ($PackagePath in $WinPEADKSE) {
                            if ($PackagePath -like "*WinPE-PowerShell*") {
                                Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray
                                Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinSE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-WinSE.log" | Out-Null
                            }
                        }
                        $WinPEADKSE = $WinPEADKSE | Where-Object {$_.Name -notlike "*WinPE-PowerShell*"}
                        foreach ($PackagePath in $WinPEADKSE) {
                            Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray
                            if ($OSMajorVersion -eq 6) {
                                dism /Image:"$MountWinSE" /Add-Package /PackagePath:"$OSBuilderContent\$PackagePath" /LogPath:"$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DISM-Add-WindowsPackage-WinSE.log"
                            } else {
                                Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinSE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-WinSE.log" | Out-Null
                            }
                        }
                    }
                }

                #===================================================================================================
                Write-Verbose '19.1.1 WinPE: (LCU) Latest Cumulative Update'
                #===================================================================================================
                if (!($Repair.IsPresent)) {
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: (LCU) Latest Cumulative Update" -ForegroundColor Green
                    if (!($null -eq $UpdateCatCumulative)) {
                        foreach ($Update in $UpdateCatCumulative) {
                            $UpdateLCU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                            if (Test-Path "$UpdateLCU") {
                                Write-Host "$UpdateLCU" -ForegroundColor DarkGray

                                #if (Get-WindowsPackage -Path "$MountWinPE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {}
                                $SessionsXmlWinPE = "$MountWinPE\Windows\Servicing\Sessions\Sessions.xml"
                                if (Test-Path $SessionsXmlWinPE) {
                                    [xml]$XmlDocument = Get-Content -Path $SessionsXmlWinPE
                                    if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.KBNumber)*" -and $_.targetState -eq 'Installed'}) {
                                        Write-Warning "WinPE.wim KB$($Update.KBNumber) is already installed"
                                    } else {
                                        $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinPE.log"
                                        Write-Verbose "$CurrentLog"
                                        Add-WindowsPackage -Path "$MountWinPE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null
                                        if (!($OSVersion -like "6.1.7601.*")) {
                                            $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinPE.log"
                                            Write-Verbose "$CurrentLog"
                                            Dism /Image:"$MountWinPE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog"
                                        }
                                    }
                                } else {
                                    $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinPE.log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountWinPE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null
                                    if (!($OSVersion -like "6.1.7601.*")) {
                                        $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinPE.log"
                                        Write-Verbose "$CurrentLog"
                                        Dism /Image:"$MountWinPE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog"
                                    }
                                }

                                #if (Get-WindowsPackage -Path "$MountWinRE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {}
                                $SessionsXmlWinRE = "$MountWinRE\Windows\Servicing\Sessions\Sessions.xml"
                                if (Test-Path $SessionsXmlWinRE) {
                                    [xml]$XmlDocument = Get-Content -Path $SessionsXmlWinRE
                                    if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.KBNumber)*" -and $_.targetState -eq 'Installed'}) {
                                        Write-Warning "WinRE.wim KB$($Update.KBNumber) is already installed"
                                    } else {
                                        $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinRE.log"
                                        Write-Verbose "$CurrentLog"
                                        Add-WindowsPackage -Path "$MountWinRE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null
                                        if (!($OSVersion -like "6.1.7601.*")) {
                                            $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinRE.log"
                                            Write-Verbose "$CurrentLog"
                                            Dism /Image:"$MountWinRE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog"
                                        }
                                    }
                                } else {
                                    $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinRE.log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountWinRE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null
                                    if (!($OSVersion -like "6.1.7601.*")) {
                                        $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinRE.log"
                                        Write-Verbose "$CurrentLog"
                                        Dism /Image:"$MountWinRE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog"
                                    }
                                }

                                #if (Get-WindowsPackage -Path "$MountWinSE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {}
                                $SessionsXmlSetup = "$MountWinSE\Windows\Servicing\Sessions\Sessions.xml"
                                if (Test-Path $SessionsXmlSetup) {
                                    [xml]$XmlDocument = Get-Content -Path $SessionsXmlSetup
                                    if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.KBNumber)*" -and $_.targetState -eq 'Installed'}) {
                                        Write-Warning "WinSE.wim KB$($Update.KBNumber) is already installed"
                                    } else {
                                        $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinSE.log"
                                        Write-Verbose "$CurrentLog"
                                        Add-WindowsPackage -Path "$MountWinSE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null
                                        if (!($OSVersion -like "6.1.7601.*")) {
                                            $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinSE.log"
                                            Write-Verbose "$CurrentLog"
                                            Dism /Image:"$MountWinSE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog"
                                        }
                                    }
                                } else {
                                    $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinSE.log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountWinSE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null
                                    if (!($OSVersion -like "6.1.7601.*")) {
                                        $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinSE.log"
                                        Write-Verbose "$CurrentLog"
                                        Dism /Image:"$MountWinSE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog"
                                    }
                                }
                            } else {
                                Write-Warning "Not Found: $UpdateLCU"
                            }
                        }
                    }
                }

                #===================================================================================================
                Write-Verbose '19.1.1 WinPE Windows 7 Updates'
                #===================================================================================================
                if (!($Repair.IsPresent)) {
                    if ($OSVersion -like "6.1.7601.*") {
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "WinPE Windows 7 Updates" -ForegroundColor Green
                        if (!($null -eq $CatalogWindows7WinPE)) {
                            foreach ($Update in $CatalogWindows7WinPE) {
                                $UpdateWin7WinPE = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                                if (Test-Path "$UpdateWin7WinPE") {
                                    Write-Host "$UpdateWin7WinPE" -ForegroundColor DarkGray

                                    if (Get-WindowsPackage -Path "$MountWinSE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {
                                        Write-Warning "WinSE.wim KB$($Update.KBNumber) is already installed"
                                    } else {
                                        $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateWin7WinPE-KB$($Update.KBNumber)-WinSE.log"
                                        Write-Verbose "$CurrentLog"
                                        Add-WindowsPackage -Path "$MountWinSE" -PackagePath "$UpdateWin7WinPE" -LogPath "$CurrentLog" | Out-Null
                                    }

                                    if (Get-WindowsPackage -Path "$MountWinPE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {
                                        Write-Warning "WinPE.wim KB$($Update.KBNumber) is already installed"
                                    } else {
                                        $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateWin7WinPE-KB$($Update.KBNumber)-WinPE.log"
                                        Write-Verbose "$CurrentLog"
                                        Add-WindowsPackage -Path "$MountWinPE" -PackagePath "$UpdateWin7WinPE" -LogPath "$CurrentLog" | Out-Null
                                    }

                                    if (Get-WindowsPackage -Path "$MountWinRE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {
                                        Write-Warning "WinRE.wim KB$($Update.KBNumber) is already installed"
                                    } else {
                                        $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateWin7WinPE-KB$($Update.KBNumber)-WinRE.log"
                                        Write-Verbose "$CurrentLog"
                                        Add-WindowsPackage -Path "$MountWinRE" -PackagePath "$UpdateWin7WinPE" -LogPath "$CurrentLog" | Out-Null
                                    }
                                } else {
                                    Write-Warning "Not Found: $UpdateWin7WinPE ... Skipping Update"
                                }
                            }
                        }
                    }
                }

                if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {
                    #===================================================================================================
                    Write-Verbose '19.1.1 WinPE DaRT'
                    # OSBuild Only
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: Microsoft DaRT" -ForegroundColor Green
                    if ($WinPEDaRT) {
                        if ([string]::IsNullOrEmpty($WinPEDaRT) -or [string]::IsNullOrWhiteSpace($WinPEDaRT)) {Write-Warning "Skipping WinPE DaRT"}
                        elseif (Test-Path "$OSBuilderContent\$WinPEDaRT") {
                            #===================================================================================================
                            Write-Host "WinPE: WinPE.wim Microsoft DaRT $OSBuilderContent\$WinPEDaRT" -ForegroundColor Green
                            expand.exe "$OSBuilderContent\$WinPEDaRT" -F:*.* "$MountWinPE"
                            if (Test-Path "$MountWinPE\Windows\System32\winpeshl.ini") {Remove-Item -Path "$MountWinPE\Windows\System32\winpeshl.ini" -Force}
                            #===================================================================================================
                            Write-Host "WinPE: WinRE.wim Microsoft DaRT $OSBuilderContent\$WinPEDaRT" -ForegroundColor Green
                            expand.exe "$OSBuilderContent\$WinPEDaRT" -F:*.* "$MountWinRE"
                            (Get-Content "$MountWinRE\Windows\System32\winpeshl.ini") | ForEach-Object {$_ -replace '-prompt','-network'} | Out-File "$MountWinRE\Windows\System32\winpeshl.ini"
                            #===================================================================================================
                            Write-Host "WinPE: WinSE.wim Microsoft DaRT $OSBuilderContent\$WinPEDaRT" -ForegroundColor Green
                            expand.exe "$OSBuilderContent\$WinPEDaRT" -F:*.* "$MountWinSE"
                            if (Test-Path "$MountWinSE\Windows\System32\winpeshl.ini") {Remove-Item -Path "$MountWinSE\Windows\System32\winpeshl.ini" -Force}
                            
                            if (Test-Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig.dat')) {
                                Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig.dat') -Destination "$MountWinPE\Windows\System32\DartConfig.dat" -Force | Out-Null
                                Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig.dat') -Destination "$MountWinSE\Windows\System32\DartConfig.dat" -Force | Out-Null
                                Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig.dat') -Destination "$MountWinRE\Windows\System32\DartConfig.dat" -Force | Out-Null
                            } elseif (Test-Path $(Join-Path $(Split-Path $WinPEDart) 'DartConfig8.dat')) {
                                Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig8.dat') -Destination "$MountWinSE\Windows\System32\DartConfig.dat" -Force | Out-Null
                                Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig8.dat') -Destination "$MountWinPE\Windows\System32\DartConfig.dat" -Force | Out-Null
                                Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig8.dat') -Destination "$MountWinRE\Windows\System32\DartConfig.dat" -Force | Out-Null
                            }
                            #===================================================================================================
                        } else {Write-Warning "WinPE DaRT do not exist in $OSBuilderContent\$WinPEDart"}
                    }
                    
                    #===================================================================================================
                    Write-Verbose '19.1.1 Extra Files'
                    # OSBuild Only
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: WinPE.wim Extra Files" -ForegroundColor Green
                    foreach ($ExtraFile in $WinPEExtraFilesPE) {robocopy "$OSBuilderContent\$ExtraFile" "$MountWinPE" *.* /e /ndl /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ExtraFiles-WinPE.log" | Out-Null}
                    #Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: WinRE.wim Extra Files" -ForegroundColor Green
                    foreach ($ExtraFile in $WinPEExtraFilesRE) {robocopy "$OSBuilderContent\$ExtraFile" "$MountWinRE" *.* /e /ndl /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ExtraFiles-WinRE.log" | Out-Null}
                    #Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: WinSE.wim Extra Files" -ForegroundColor Green
                    foreach ($ExtraFile in $WinPEExtraFilesSE) {robocopy "$OSBuilderContent\$ExtraFile" "$MountWinSE" *.* /e /ndl /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ExtraFiles-WinSE.log" | Out-Null}
                                        
                    #===================================================================================================
                    Write-Verbose '19.1.9 Auto Extra Files'
                    # OSBuild Only
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: WinPE.wim Auto ExtraFiles" -ForegroundColor Green
                    if ($WinPEAutoExtraFiles -eq $true) {
                        robocopy "$WinPE\AutoExtraFiles" "$MountWinPE" *.* /e /ndl /xf bcp47*.dll /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-AutoExtraFiles-WinPE.log" | Out-Null
                    }
                    Write-Host "WinPE: WinRE.wim Auto ExtraFiles" -ForegroundColor Green
                    if ($WinPEAutoExtraFiles -eq $true) {
                        robocopy "$WinPE\AutoExtraFiles" "$MountWinRE" *.* /e /ndl /xf bcp47*.dll /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-AutoExtraFiles-WinRE.log" | Out-Null
                    }
                    Write-Host "WinPE: WinSE.wim Auto ExtraFiles" -ForegroundColor Green
                    if ($WinPEAutoExtraFiles -eq $true) {
                        robocopy "$WinPE\AutoExtraFiles" "$MountWinSE" *.* /e /ndl /xf bcp47*.dll /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-AutoExtraFiles-WinSE.log" | Out-Null
                    }

                    #===================================================================================================
                    Write-Verbose '19.1.1 Drivers'
                    # OSBuild Only
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: WinPE.wim Drivers" -ForegroundColor Green
                    foreach ($WinPEDriver in $WinPEDrivers) {
                        Write-Host "$OSBuilderContent\$WinPEDriver" -ForegroundColor DarkGray
                        if ($OSMajorVersion -eq 6) {
                            dism /Image:"$MountWinPE" /Add-Driver /Driver:"$OSBuilderContent\$WinPEDriver" /Recurse /ForceUnsigned /LogPath:"$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DISM-Add-Driver-WinPE.log"
                        } else {
                            Add-WindowsDriver -Path "$MountWinPE" -Driver "$OSBuilderContent\$WinPEDriver" -Recurse -ForceUnsigned -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsDriver-WinPE.log" | Out-Null
                        }
                    }
                    #Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: WinRE.wim Drivers" -ForegroundColor Green
                    foreach ($WinPEDriver in $WinPEDrivers) {
                        Write-Host "$OSBuilderContent\$WinPEDriver" -ForegroundColor DarkGray
                        if ($OSMajorVersion -eq 6) {
                            dism /Image:"$MountWinRE" /Add-Driver /Driver:"$OSBuilderContent\$WinPEDriver" /Recurse /ForceUnsigned /LogPath:"$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DISM-Add-Driver-WinRE.log"
                        } else {
                            Add-WindowsDriver -Path "$MountWinRE" -Driver "$OSBuilderContent\$WinPEDriver" -Recurse -ForceUnsigned -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsDriver-WinRE.log" | Out-Null
                        }
                    }
                    #Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: WinSE.wim Drivers" -ForegroundColor Green
                    foreach ($WinPEDriver in $WinPEDrivers) {
                        Write-Host "$OSBuilderContent\$WinPEDriver" -ForegroundColor DarkGray
                        if ($OSMajorVersion -eq 6) {
                            dism /Image:"$MountWinSE" /Add-Driver /Driver:"$OSBuilderContent\$WinPEDriver" /Recurse /ForceUnsigned /LogPath:"$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DISM-Add-Driver-WinSE.log"
                        } else {
                            Add-WindowsDriver -Path "$MountWinSE" -Driver "$OSBuilderContent\$WinPEDriver" -Recurse -ForceUnsigned -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsDriver-WinSE.log" | Out-Null
                        }
                    }
                    
                    #===================================================================================================
                    # Write-Verbose '19.1.16 PowerShell Scripts'
                    # OSBuild Only
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "WinPE: WinPE.wim PowerShell Scripts" -ForegroundColor Green
                    foreach ($PSWimScript in $WinPEScriptsPE) {
                        if (Test-Path "$OSBuilderContent\$PSWimScript") {
                            Write-Host "PowerShell Script: $OSBuilderContent\$PSWimScript" -ForegroundColor DarkGray
                            (Get-Content "$OSBuilderContent\$PSWimScript").replace('winpe.wim.log', 'WinPE.log') | Set-Content "$OSBuilderContent\$PSWimScript"
                            Invoke-Expression "& '$OSBuilderContent\$PSWimScript'"
                        }
                    }
                    Write-Host "WinPE: WinRE.wim PowerShell Scripts" -ForegroundColor Green
                    foreach ($PSWimScript in $WinPEScriptsRE) {
                        if (Test-Path "$OSBuilderContent\$PSWimScript") {
                            Write-Host "PowerShell Script: $OSBuilderContent\$PSWimScript" -ForegroundColor DarkGray
                            (Get-Content "$OSBuilderContent\$PSWimScript").replace('winre.wim.log', 'WinRE.log') | Set-Content "$OSBuilderContent\$PSWimScript"
                            Invoke-Expression "& '$OSBuilderContent\$PSWimScript'"
                        }
                    }
                    Write-Host "WinPE: WinSE.wim PowerShell Scripts" -ForegroundColor Green
                    foreach ($PSWimScript in $WinPEScriptsSE) {
                        if (Test-Path "$OSBuilderContent\$PSWimScript") {
                            Write-Host "PowerShell Script: $OSBuilderContent\$PSWimScript" -ForegroundColor DarkGray
                            (Get-Content "$OSBuilderContent\$PSWimScript").replace('MountSetup', 'MountWinSE') | Set-Content "$OSBuilderContent\$PSWimScript"
                            (Get-Content "$OSBuilderContent\$PSWimScript").replace('setup.wim.log', 'WinSE.log') | Set-Content "$OSBuilderContent\$PSWimScript"
                            Invoke-Expression "& '$OSBuilderContent\$PSWimScript'"
                        }
                    }
                }

                #===================================================================================================
                Write-Verbose '19.1.1 Update-OSBWinPESources'
                #===================================================================================================
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                Update-OSBWinPESources -OSMediaPath "$WorkingPath" -MountWinSE "$MountWinSE"

                #===================================================================================================
                Write-Verbose '19.1.1 Export-OSBWinPEPackages'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                Export-OSBWinPEPackages -OSMediaPath "$WorkingPath" -MountWinPE "$MountWinPE" -MountWinRE "$MountWinRE" -MountWinSE "$MountWinSE"

                #===================================================================================================
                Write-Verbose '19.1.1 Prompt Before Dismount'
                #===================================================================================================
                if ($PromptBeforeDismountWinPE.IsPresent){[void](Read-Host 'Press Enter to Continue')}

                #===================================================================================================
                Write-Verbose '19.1.1 Dismount-OSBWinPE'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                Dismount-OSBWinPE -OSMediaPath "$WorkingPath" -MountWinPE "$MountWinPE" -MountWinRE "$MountWinRE" -MountWinSE "$MountWinSE"

                #===================================================================================================
                Write-Verbose '19.1.1 Export-OSBWinPE'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                Export-OSBWinPE -OSMediaPath "$WorkingPath" -MountWinPE "$MountWinPE" -MountWinRE "$MountWinRE" -MountWinSE "$MountWinSE"

                #===================================================================================================
                Write-Verbose '19.1.1 Export-OSBWinPEBootWim'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                Export-OSBWinPEBootWim -OSMediaPath "$WorkingPath"

                #===================================================================================================
                Write-Verbose '19.1.1 Export-OSBWinPEInventory'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                Export-OSBWinPEInventory -OSMediaPath "$WorkingPath"

                #===================================================================================================
                Write-Verbose '19.1.1 Install.wim: Mount'
                #===================================================================================================
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Host "Install.wim: Mount to $MountDirectory" -ForegroundColor Green
                $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Mount-WindowsImage.log"
                Write-Verbose "$CurrentLog"
                Mount-WindowsImage -ImagePath "$WimTemp\install.wim" -Index 1 -Path "$MountDirectory" -LogPath "$CurrentLog" | Out-Null

                #===================================================================================================
                Write-Verbose '19.1.1 Install.wim: Mount Registry for UBR Information'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Host "Install.wim: Mount Registry for UBR Information" -ForegroundColor Green

                reg LOAD 'HKLM\OSMedia' "$MountDirectory\Windows\System32\Config\SOFTWARE" | Out-Null
                $RegCurrentVersion = Get-ItemProperty -Path 'HKLM:\OSMedia\Microsoft\Windows NT\CurrentVersion'
                reg UNLOAD 'HKLM\OSMedia' | Out-Null

                $OSVersionNumber = $null
                $OSVersionNumber = $($RegCurrentVersion.ReleaseId)
                $RegCurrentVersionUBR = $($RegCurrentVersion.UBR)
                $UBR = "$OSBuild.$RegCurrentVersionUBR"

                $RegCurrentVersion | Out-File "$Info\CurrentVersion.txt"
                $RegCurrentVersion | Out-File "$WorkingPath\CurrentVersion.txt"
                $RegCurrentVersion | Out-File "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-CurrentVersion.txt"
                $RegCurrentVersion | Export-Clixml -Path "$Info\xml\CurrentVersion.xml"
                $RegCurrentVersion | Export-Clixml -Path "$Info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-CurrentVersion.xml"
                $RegCurrentVersion | ConvertTo-Json | Out-File "$Info\json\CurrentVersion.json"
                $RegCurrentVersion | ConvertTo-Json | Out-File "$Info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-CurrentVersion.json"

                #===================================================================================================
                Write-Verbose '19.1.1 Install.wim: Replace WinRE'
                #===================================================================================================
                if (!($Repair.IsPresent)) {
                    #Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: Replace $MountDirectory\Windows\System32\Recovery\winre.wim" -ForegroundColor Green
                    if (Test-Path "$MountDirectory\Windows\System32\Recovery\winre.wim") {
                        Remove-Item -Path "$MountDirectory\Windows\System32\Recovery\winre.wim" -Force
                    }

                    Copy-Item -Path "$WinPE\winre.wim" -Destination "$MountDirectory\Windows\System32\Recovery\winre.wim" -Force | Out-Null

                    $GetWindowsImage = Get-WindowsImage -ImagePath "$WinPE\winre.wim" -Index 1 | Select-Object -Property *
                    $GetWindowsImage | Out-File "$PEInfo\Get-WindowsImage-WinRE.txt"
                    (Get-Content "$PEInfo\Get-WindowsImage-WinRE.txt") | Where-Object {$_.Trim(" `t")} | Set-Content "$PEInfo\Get-WindowsImage-WinRE.txt"
                    $GetWindowsImage | Out-File "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-WinRE.txt"
                    $GetWindowsImage | Export-Clixml -Path "$PEInfo\xml\Get-WindowsImage-WinRE.xml"
                    $GetWindowsImage | Export-Clixml -Path "$PEInfo\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-WinRE.xml"
                    $GetWindowsImage | ConvertTo-Json | Out-File "$PEInfo\json\Get-WindowsImage-WinRE.json"
                    $GetWindowsImage | ConvertTo-Json | Out-File "$PEInfo\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-WinRE.json"
                }
                
                #===================================================================================================
                Write-Verbose '19.1.1 Install.wim: (SSU) Servicing Stack Update'
                #===================================================================================================
                if (!($Repair.IsPresent)) {
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: (SSU) Servicing Stack Update" -ForegroundColor Green
                    if (!($null -eq $UpdateCatServicing)) {
                        foreach ($Update in $UpdateCatServicing) {
                            $UpdateSSU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                            if (Test-Path "$UpdateSSU") {
                                Write-Host "$UpdateSSU" -ForegroundColor DarkGray
                                if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {
                                    Write-Warning "KB$($Update.KBNumber) is already installed"
                                } else {
                                    $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ServicingStack-KB$($Update.KBNumber).log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateSSU" -LogPath "$CurrentLog" | Out-Null
                                }
                            } else {
                                Write-Warning "Not Found: $UpdateSSU"
                            }
                        }
                    }
                }

                #===================================================================================================
                Write-Verbose '19.1.1 Install.wim: Component Update'
                #===================================================================================================
                if (!($Repair.IsPresent)) {
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: Component Update" -ForegroundColor Green
                    if (!($null -eq $UpdateCatComponent)) {
                        foreach ($Update in $UpdateCatComponent) {
                            $UpdateComp = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                            if (Test-Path "$UpdateComp") {
                                Write-Host "$UpdateComp" -ForegroundColor DarkGray
                                if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {
                                    Write-Warning "KB$($Update.KBNumber) is already installed"
                                } else {
                                    $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Component-KB$($Update.KBNumber).log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateComp" -LogPath "$CurrentLog" | Out-Null
                                }
                            } else {
                                Write-Warning "Not Found: $UpdateComp"
                            }
                        }
                    }
                }

                #===================================================================================================
                Write-Verbose '19.1.1 Install.wim: Update Build Revision (Pre-LCU)'
                #===================================================================================================
                $UBRPre = $UBR
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                #Write-Host "Install.wim: Update Build Revision $UBRPre (Pre-LCU)" -ForegroundColor Yellow

                #===================================================================================================
                Write-Verbose '19.1.1 Install.wim: (LCU) Latest Cumulative Update'
                #===================================================================================================
                if (!($Repair.IsPresent)) {
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: (LCU) Latest Cumulative Update (Pre-LCU UBR $UBRPre)" -ForegroundColor Green
                    if (!($null -eq $UpdateCatCumulative)) {
                        foreach ($Update in $UpdateCatCumulative) {
                            $UpdateLCU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                            if (Test-Path "$UpdateLCU") {
                                Write-Host "$UpdateLCU" -ForegroundColor DarkGray
                                $SessionsXmlInstall = "$MountDirectory\Windows\Servicing\Sessions\Sessions.xml"
                                if (Test-Path $SessionsXmlInstall) {
                                    [xml]$XmlDocument = Get-Content -Path $SessionsXmlInstall
                                    if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.KBNumber)*" -and $_.targetState -eq 'Installed'}) {
                                        Write-Warning "KB$($Update.KBNumber) is already installed"
                                    } else {
                                        Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateLCU" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber).log" | Out-Null
                                    }
                                } else {
                                    $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber).log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null
                                }
                            } else {
                                Write-Warning "Not Found: $UpdateLCU"
                            }
                        }
                    }
                }

                #===================================================================================================
                Write-Verbose '19.1.1 Install.wim: Registry and UBR PostInstall'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                #Write-Host "Install.wim: Registry and UBR PostInstall" -ForegroundColor Green
                reg LOAD 'HKLM\OSMedia' "$MountDirectory\Windows\System32\Config\SOFTWARE" | Out-Null
                $RegCurrentVersion = Get-ItemProperty -Path 'HKLM:\OSMedia\Microsoft\Windows NT\CurrentVersion'
                reg UNLOAD 'HKLM\OSMedia' | Out-Null

                $OSVersionNumber = $null
                $OSVersionNumber = $($RegCurrentVersion.ReleaseId)
                $RegCurrentVersionUBR = $($RegCurrentVersion.UBR)
                $UBR = "$OSBuild.$RegCurrentVersionUBR"

                $RegCurrentVersion | Out-File "$Info\CurrentVersion.txt"
                $RegCurrentVersion | Out-File "$WorkingPath\CurrentVersion.txt"
                $RegCurrentVersion | Out-File "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-CurrentVersion.txt"
                $RegCurrentVersion | Export-Clixml -Path "$Info\xml\CurrentVersion.xml"
                $RegCurrentVersion | Export-Clixml -Path "$Info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-CurrentVersion.xml"
                $RegCurrentVersion | ConvertTo-Json | Out-File "$Info\json\CurrentVersion.json"
                $RegCurrentVersion | ConvertTo-Json | Out-File "$Info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-CurrentVersion.json"

                #===================================================================================================
                Write-Verbose '19.1.1 Install.wim: Update Build Revision $UBR (Post-LCU)'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Host "Install.wim: Update Build Revision $UBR (Post-LCU)" -ForegroundColor Green

                if (!($Repair.IsPresent)) {
                
                    #===================================================================================================
                    Write-Verbose '19.1.14 Install.wim: (NetCU) DotNet Framework Cumulative'
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: (NetCU) DotNet Framework Cumulative Update" -ForegroundColor Green
                    if (!($null -eq $UpdateCatDotNet)) {
                        foreach ($Update in $UpdateCatDotNet) {
                            $UpdateNetCU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                            if (Test-Path "$UpdateNetCU") {
                                Write-Host "$UpdateNetCU" -ForegroundColor DarkGray
                                if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {
                                    Write-Warning "KB$($Update.KBNumber) is already installed"
                                } else {
                                    $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DotNet-KB$($Update.KBNumber).log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateNetCU" -LogPath "$CurrentLog" | Out-Null
                                }
                            } else {
                                Write-Warning "Not Found: $UpdateNetCU"
                            }
                        }
                    }

                    #===================================================================================================
                    Write-Verbose '19.1.1 Install.wim: (ASU) Adobe Flash Player Security Update'
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: (ASU) Adobe Flash Player Security Update" -ForegroundColor Green
                    if (!($null -eq $UpdateCatAdobe)) {
                        foreach ($Update in $UpdateCatAdobe) {
                            $UpdateASU = @()
                            $UpdateASU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                            if (Test-Path "$UpdateASU") {
                                Write-Host "$UpdateASU" -ForegroundColor DarkGray
                                if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {
                                    Write-Warning "KB$($Update.KBNumber) is already installed"
                                } else {
                                    $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-AdobeFlashPlayer-KB$($Update.KBNumber).log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateASU" -LogPath "$CurrentLog" | Out-Null
                                }
                            } else {
                                Write-Warning "Not Found: $UpdateASU"
                            }
                        }
                    }

                    #===================================================================================================
                    Write-Verbose '19.1.1 Install.wim: DISM Cleanup-Image'
                    #===================================================================================================
                    if ($OSVersion -like "10*") {
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: DISM Cleanup-Image" -ForegroundColor Green
                        if ($(Get-WindowsCapability -Path $MountDirectory | Where-Object {$_.state -eq "*pending*"})) {
                            Write-Warning "Cannot run WindowsImage Cleanup on a WIM with Pending Installations"
                        } else {
                            $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-Cleanup-Image.log"
                            Write-Verbose "$CurrentLog"
                            Dism /Image:"$MountDirectory" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog"
                        }
                    }

                    #===================================================================================================
                    Write-Verbose '19.1.1 Install.wim: Windows 7 Updates'
                    #===================================================================================================
                    if ($OSBuild -eq 7601) {
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: Windows 7 Updates" -ForegroundColor Green
                        if (!($null -eq $CatalogWindows7)) {
                            foreach ($Update in $CatalogWindows7) {
                                $UpdateWin7 = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                                if (Test-Path "$UpdateWin7") {
                                    Write-Host "$UpdateWin7" -ForegroundColor DarkGray
                                    if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {
                                        Write-Warning "KB$($Update.KBNumber) is already installed"
                                    } else {
                                        $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateWin7-KB$($Update.KBNumber).log"
                                        Write-Verbose "$CurrentLog"
                                        Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateWin7" -LogPath "$CurrentLog" | Out-Null
                                    }
                                } else {
                                    Write-Warning "Not Found: $UpdateWin7"
                                }
                            }
                        }
                    }
                }
                
                #===================================================================================================
                Write-Verbose '19.1.1 OSBuild Only'
                #===================================================================================================
                if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and $OSMajorVersion -eq 10) {

                    #===================================================================================================
                    Write-Verbose '19.1.1 OSBuild Language Packs'
                    # OSBuild Only
                    #===================================================================================================
                    if ($LanguagePacks) {
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: Language Packs"    -ForegroundColor Green
                        foreach ($Update in $LanguagePacks) {
                            if (Test-Path "$OSBuilderContent\$Update") {
                                if ($Update -like "*.cab") {
                                    Write-Host "$OSBuilderContent\$Update" -ForegroundColor DarkGray
                                    Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$OSBuilderContent\$Update" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-LanguagePack.log" | Out-Null
                                }
                            } else {
                                Write-Warning "Not Found: $OSBuilderContent\$Update"
                            }
                        }
                        if (Test-Path "$OSBuilderContent\$Update") {
                            if ($Update -like "*.appx") {
                                Write-Host "$OSBuilderContent\$Update" -ForegroundColor DarkGray
                                Add-AppxProvisionedPackage -Path "$MountDirectory" -PackagePath "$OSBuilderContent\$Update" -LicensePath "$((Get-Item $OSBuilderContent\$Update).Directory.FullName)\License.xml" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-LocalExperiencePack.log" | Out-Null
                            }
                        } else {
                            Write-Warning "Not Found: $OSBuilderContent\$Update"
                        }
                    }
                    if ($LanguageInterfacePacks) {
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: Language Interface Packs"    -ForegroundColor Green
                        foreach ($Update in $LanguageInterfacePacks) {
                            if (Test-Path "$OSBuilderContent\$Update") {
                                Write-Host "$OSBuilderContent\$Update" -ForegroundColor DarkGray
                                Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$OSBuilderContent\$Update" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-LanguageInterfacePack.log" | Out-Null
                            } else {
                                Write-Warning "Not Found: $OSBuilderContent\$Update"
                            }
                        }
                    }
                    if ($LocalExperiencePacks) {
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: Local Experience Packs"    -ForegroundColor Green
                        foreach ($Update in $LocalExperiencePacks) {
                            if (Test-Path "$OSBuilderContent\$Update") {
                                Write-Host "$OSBuilderContent\$Update" -ForegroundColor DarkGray
                                Add-AppxProvisionedPackage -Path "$MountDirectory" -PackagePath "$OSBuilderContent\$Update" -LicensePath "$((Get-Item $OSBuilderContent\$Update).Directory.FullName)\License.xml" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-LocalExperiencePack.log" | Out-Null
                            } else {
                                Write-Warning "Not Found: $OSBuilderContent\$Update"
                            }
                        }
                    }
                    if ($LanguageFeatures) {
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: Language Features"    -ForegroundColor Green
                        foreach ($Update in $LanguageFeatures | Where-Object {$_ -notlike "*Speech*"}) {
                            if (Test-Path "$OSBuilderContent\$Update") {
                                Write-Host "$OSBuilderContent\$Update" -ForegroundColor DarkGray
                                Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$OSBuilderContent\$Update" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-LanguageFeatures.log" | Out-Null
                            }
                        }
                        foreach ($Update in $LanguageFeatures | Where-Object {$_ -like "*TextToSpeech*"}) {
                            if (Test-Path "$OSBuilderContent\$Update") {
                                Write-Host "$OSBuilderContent\$Update" -ForegroundColor DarkGray
                                Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$OSBuilderContent\$Update" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-LanguageFeatures.log" | Out-Null
                            }
                        }
                        foreach ($Update in $LanguageFeatures | Where-Object {$_ -like "*Speech*" -and $_ -notlike "*TextToSpeech*"}) {
                            if (Test-Path "$OSBuilderContent\$Update") {
                                Write-Host "$OSBuilderContent\$Update" -ForegroundColor DarkGray
                                Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$OSBuilderContent\$Update" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-LanguageFeatures.log" | Out-Null
                            }
                        }
                    }

                    if ($LanguagePacks -or $LanguageInterfacePacks -or $LanguageFeatures -or $LocalExperiencePacks) {
                        #===================================================================================================
                        Write-Verbose '19.1.1 Install.wim: Generating Langini'
                        #===================================================================================================
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: Generating Updated Langini" -ForegroundColor Green
                        Dism /Image:"$MountDirectory" /Gen-LangIni /Distribution:"$OS" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-gen-langini.log" | Out-Null
                        #===================================================================================================
                        Write-Verbose '19.1.1 Install.wim: Set Language Settings'
                        #===================================================================================================
                        if ($SetAllIntl) {
                            #Write-Host '========================================================================================' -ForegroundColor DarkGray
                            Write-Host "Install.wim: SetAllIntl" -ForegroundColor Green
                            Dism /Image:"$MountDirectory" /Set-AllIntl:"$SetAllIntl" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetAllIntl.log" | Out-Null
                        }
                        if ($SetInputLocale) {
                            #Write-Host '========================================================================================' -ForegroundColor DarkGray
                            Write-Host "Install.wim: SetInputLocale" -ForegroundColor Green
                            Dism /Image:"$MountDirectory" /Set-InputLocale:"$SetInputLocale" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetInputLocale.log" | Out-Null
                        }
                        if ($SetSKUIntlDefaults) {
                            #Write-Host '========================================================================================' -ForegroundColor DarkGray
                            Write-Host "Install.wim: SetSKUIntlDefaults" -ForegroundColor Green
                            Dism /Image:"$MountDirectory" /Set-SKUIntlDefaults:"$SetSKUIntlDefaults" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetSKUIntlDefaults.log" | Out-Null
                        }
                        if ($SetSetupUILang) {
                            #Write-Host '========================================================================================' -ForegroundColor DarkGray
                            Write-Host "Install.wim: SetSetupUILang" -ForegroundColor Green
                            Dism /Image:"$MountDirectory" /Set-SetupUILang:"$SetSetupUILang" /Distribution:"$OS" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetSetupUILang.log" | Out-Null
                        }
                        if ($SetSysLocale) {
                            #Write-Host '========================================================================================' -ForegroundColor DarkGray
                            Write-Host "Install.wim: SetSysLocale" -ForegroundColor Green
                            Dism /Image:"$MountDirectory" /Set-SysLocale:"$SetSysLocale" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetSysLocale.log" | Out-Null
                        }
                        if ($SetUILang) {
                            #Write-Host '========================================================================================' -ForegroundColor DarkGray
                            Write-Host "Install.wim: SetUILang" -ForegroundColor Green
                            Dism /Image:"$MountDirectory" /Set-UILang:"$SetUILang" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetUILang.log" | Out-Null
                        }
                        if ($SetUILangFallback) {
                            #Write-Host '========================================================================================' -ForegroundColor DarkGray
                            Write-Host "Install.wim: SetUILangFallback" -ForegroundColor Green
                            Dism /Image:"$MountDirectory" /Set-UILangFallback:"$SetUILangFallback" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetUILangFallback.log" | Out-Null
                        }
                        if ($SetUserLocale) {
                            #Write-Host '========================================================================================' -ForegroundColor DarkGray
                            Write-Host "Install.wim: SetUserLocale" -ForegroundColor Green
                            Dism /Image:"$MountDirectory" /Set-UserLocale:"$SetUserLocale" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetUserLocale.log" | Out-Null
                        }
                        #===================================================================================================
                        Write-Verbose '19.1.1 Install.wim: (LCU) Latest Cumulative Update'
                        #===================================================================================================
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: LCU (Latest Cumulative Update)" -ForegroundColor Green
                        if (!($null -eq $UpdateCatCumulative)) {
                            foreach ($Update in $UpdateCatCumulative) {
                                $UpdateCU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                                if (Test-Path "$UpdateCU") {
                                    Write-Host "Install.wim: $UpdateCU" -ForegroundColor DarkGray
                                    $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Cumulative-KB$($Update.KBNumber).log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateCU" -LogPath "$CurrentLog" | Out-Null
                                } else {
                                    Write-Warning "Not Found: $UpdateCU"
                                }
                            }
                        }

                        #===================================================================================================
                        Write-Verbose '19.1.1 Install.wim: DISM Cleanup-Image'
                        #===================================================================================================
                        if ($OSMajorVersion -eq 10) {
                            Write-Host '========================================================================================' -ForegroundColor DarkGray
                            Write-Host "Install.wim: DISM Cleanup-Image" -ForegroundColor Green
                            if ($(Get-WindowsCapability -Path $MountDirectory | Where-Object {$_.state -eq "*pending*"})) {
                                Write-Warning "Cannot run WindowsImage Cleanup on a WIM with Pending Installations"
                            } else {
                                $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-Cleanup-Image.log"
                                Write-Verbose "$CurrentLog"
                                Dism /Image:"$MountDirectory" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog"
                            }
                        }
                    }
                }

                if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {
                    #===================================================================================================
                    Write-Verbose '19.1.17 OSBuild Features On Demand'
                    #===================================================================================================
                    if ($FeaturesOnDemand) {
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: Features On Demand"    -ForegroundColor Green
                        foreach ($FOD in $FeaturesOnDemand) {
                            Write-Host $FOD -ForegroundColor DarkGray
                            $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-FOD.log"
                            Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$OSBuilderContent\$FOD" -LogPath "$CurrentLog" | Out-Null
                        }
                        #===================================================================================================
                        Write-Verbose '19.1.1 Install.wim: (LCU) Latest Cumulative Update'
                        #===================================================================================================
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: LCU (Latest Cumulative Update)" -ForegroundColor Green
                        if (!($null -eq $UpdateCatCumulative)) {
                            foreach ($Update in $UpdateCatCumulative) {
                                $UpdateCU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                                if (Test-Path "$UpdateCU") {
                                    Write-Host "Install.wim: $UpdateCU" -ForegroundColor DarkGray
                                    $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Cumulative-KB$($Update.KBNumber).log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateCU" -LogPath "$CurrentLog" | Out-Null
                                } else {
                                    Write-Warning "Not Found: $UpdateCU"
                                }
                            }
                        }
                        #===================================================================================================
                        Write-Verbose '19.1.1 Install.wim: DISM Cleanup-Image'
                        #===================================================================================================
                        if ($OSVersion -like "10*") {
                            Write-Host '========================================================================================' -ForegroundColor DarkGray
                            Write-Host "Install.wim: DISM Cleanup-Image" -ForegroundColor Green
                            if ($(Get-WindowsCapability -Path $MountDirectory | Where-Object {$_.state -eq "*pending*"})) {
                                Write-Warning "Cannot run WindowsImage Cleanup on a WIM with Pending Installations"
                            } else {
                                $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-Cleanup-Image.log"
                                Write-Verbose "$CurrentLog"
                                Dism /Image:"$MountDirectory" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog"
                            }
                        }
                    }
                }

                if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {
                    #===================================================================================================
                    Write-Verbose '19.1.1 OSBuild Windows Optional Features'
                    #===================================================================================================
                    if ($EnableFeature) {
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: Enable Windows Optional Feature"    -ForegroundColor Green
                        foreach ($FeatureName in $EnableFeature) {
                            Write-Host $FeatureName -ForegroundColor DarkGray
                            Enable-WindowsOptionalFeature -FeatureName $FeatureName -Path "$MountDirectory" -All -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Enable-WindowsOptionalFeature.log" | Out-Null
                        }
                        
                        if ($OSMajorVersion -eq 10) {
                            #===================================================================================================
                            Write-Verbose '19.1.1 Install.wim: (LCU) Latest Cumulative Update'
                            #===================================================================================================
                            Write-Host '========================================================================================' -ForegroundColor DarkGray
                            Write-Host "Install.wim: LCU (Latest Cumulative Update)" -ForegroundColor Green
                            if (!($null -eq $UpdateCatCumulative)) {
                                foreach ($Update in $UpdateCatCumulative) {
                                    $UpdateCU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                                    if (Test-Path "$UpdateCU") {
                                        Write-Host "Install.wim: $UpdateCU" -ForegroundColor DarkGray
                                        $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Cumulative-KB$($Update.KBNumber).log"
                                        Write-Verbose "$CurrentLog"
                                        Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateCU" -LogPath "$CurrentLog" | Out-Null
                                    } else {
                                        Write-Warning "Not Found: $UpdateCU"
                                    }
                                }
                            }

                            #===================================================================================================
                            Write-Verbose '19.1.1 Install.wim: DISM Cleanup-Image'
                            #===================================================================================================
                            if ($OSVersion -like "10*") {
                                Write-Host '========================================================================================' -ForegroundColor DarkGray
                                Write-Host "Install.wim: DISM Cleanup-Image" -ForegroundColor Green
                                if ($(Get-WindowsCapability -Path $MountDirectory | Where-Object {$_.state -eq "*pending*"})) {
                                    Write-Warning "Cannot run WindowsImage Cleanup on a WIM with Pending Installations"
                                } else {
                                    $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-Cleanup-Image.log"
                                    Write-Verbose "$CurrentLog"
                                    Dism /Image:"$MountDirectory" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog"
                                }
                            }
                        }
                        
                        #===================================================================================================
                        Write-Verbose '19.1.1 Install.wim: Windows 7 Updates'
                        #===================================================================================================
                        if ($OSBuild -eq 7601) {
                            Write-Host '========================================================================================' -ForegroundColor DarkGray
                            Write-Host "Install.wim: Windows 7 Updates" -ForegroundColor Green
                            if (!($null -eq $CatalogWindows7)) {
                                foreach ($Update in $CatalogWindows7) {
                                    $UpdateWin7 = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                                    if (Test-Path "$UpdateWin7") {
                                        Write-Host "$UpdateWin7" -ForegroundColor DarkGray
                                        if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {
                                            Write-Warning "KB$($Update.KBNumber) is already installed"
                                        } else {
                                            $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateWin7-KB$($Update.KBNumber).log"
                                            Write-Verbose "$CurrentLog"
                                            Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateWin7" -LogPath "$CurrentLog" | Out-Null
                                        }
                                    } else {
                                        Write-Warning "Not Found: $UpdateWin7"
                                    }
                                }
                            }
                        }
                    }

                    #===================================================================================================
                    Write-Verbose '19.1.1 OSBuild EnableNetFX3'
                    #===================================================================================================
                    if ($EnableNetFX3 -eq 'True' -and $OSMajorVersion -eq 10) {
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: Enable NetFX 3.5"    -ForegroundColor Green
                        Enable-WindowsOptionalFeature -Path "$MountDirectory" -FeatureName NetFX3 -All -LimitAccess -Source "$OS\sources\sxs" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-NetFX3.log" | Out-Null
                        #===================================================================================================
                        Write-Verbose '19.1.14 Install.wim: (NetCU) DotNet Framework Cumulative'
                        #===================================================================================================
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: (NetCU) DotNet Framework Cumulative Update" -ForegroundColor Green
                        if (!($null -eq $UpdateCatDotNet)) {
                            foreach ($Update in $UpdateCatDotNet) {
                                $UpdateNetCU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                                if (Test-Path "$UpdateNetCU") {
                                    Write-Host "$UpdateNetCU" -ForegroundColor DarkGray
                                    $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DotNet-KB$($Update.KBNumber).log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateNetCU" -LogPath "$CurrentLog" | Out-Null
                                } else {
                                    Write-Warning "Not Found: $UpdateNetCU"
                                }
                            }
                        }
                        #===================================================================================================
                        Write-Verbose '19.1.1 Install.wim: (LCU) Latest Cumulative Update'
                        #===================================================================================================
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Host "Install.wim: (LCU) Latest Cumulative Update" -ForegroundColor Green
                        if (!($null -eq $UpdateCatCumulative)) {
                            foreach ($Update in $UpdateCatCumulative) {
                                $UpdateCU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName
                                if (Test-Path "$UpdateCU") {
                                    Write-Host "$UpdateCU" -ForegroundColor DarkGray
                                    $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Cumulative-KB$($Update.KBNumber).log"
                                    Write-Verbose "$CurrentLog"
                                    Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateCU" -LogPath "$CurrentLog" | Out-Null
                                } else {
                                    Write-Warning "Not Found: $UpdateCU"
                                }
                            }
                        }
                    }

                    #===================================================================================================
                    Write-Verbose '19.1.1 Remove Appx Packages'
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: Remove Appx Packages"    -ForegroundColor Green
                    if ($RemoveAppx -and $OSMajorVersion -eq 10) {
                        foreach ($item in $RemoveAppx) {
                            Write-Host $item -ForegroundColor DarkGray
                            Remove-AppxProvisionedPackage -Path "$MountDirectory" -PackageName $item -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Remove-AppxProvisionedPackage.log" | Out-Null
                        }
                    }
                    #===================================================================================================
                    Write-Verbose '19.1.1 Remove Packages'
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: Remove Windows Packages"    -ForegroundColor Green
                    if ($RemovePackage) {
                        foreach ($PackageName in $RemovePackage) {
                            Write-Host $item -ForegroundColor DarkGray
                            Remove-WindowsPackage -Path "$MountDirectory" -PackageName $PackageName -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Remove-WindowsPackage.log" | Out-Null
                        }
                    }
                    #===================================================================================================
                    Write-Verbose '19.1.1 Remove Capability'
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: Remove Windows Capability"    -ForegroundColor Green
                    if ($RemoveCapability) {
                        foreach ($Name in $RemoveCapability) {
                            Write-Host $Name -ForegroundColor DarkGray
                            Remove-WindowsCapability -Path "$MountDirectory" -Name $Name -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Remove-WindowsCapability.log" | Out-Null
                        }
                    }
                    #===================================================================================================
                    Write-Verbose '19.1.1 Disable Windows Optional Feature'
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: Disable Windows Optional Feature" -ForegroundColor Green
                    if ($DisableFeature) {
                        foreach ($FeatureName in $DisableFeature) {
                            Write-Host $FeatureName -ForegroundColor DarkGray
                            Disable-WindowsOptionalFeature -FeatureName $FeatureName -Path "$MountDirectory" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Disable-WindowsOptionalFeature.log" | Out-Null
                        }
                    }
                    #===================================================================================================
                    Write-Verbose '19.1.1 Add Packages'
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: Add Packages"    -ForegroundColor Green
                    if ($Packages) {
                        foreach ($PackagePath in $Packages) {
                            Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray
                            Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountDirectory" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage.log" | Out-Null
                        }
                    }
                    #===================================================================================================
                    Write-Verbose '19.1.11 Add Drivers'
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: Add Drivers"    -ForegroundColor Green
                    if ($Drivers) {
                        foreach ($Driver in $Drivers) {
                            Write-Host "$OSBuilderContent\$Driver" -ForegroundColor DarkGray
                            if ($OSMajorVersion -eq 6) {
                                dism /Image:"$MountDirectory" /Add-Driver /Driver:"$OSBuilderContent\$Driver" /Recurse /ForceUnsigned /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DISM-Add-Driver.log"
                            } else {

                                Add-WindowsDriver -Driver "$OSBuilderContent\$Driver" -Recurse -Path "$MountDirectory" -ForceUnsigned -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsDriver.log" | Out-Null
                            }
                        }
                    }
                    #===================================================================================================
                    Write-Verbose '19.1.1 Extra Files'
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: Extra Files"    -ForegroundColor Green
                    if ($ExtraFiles) {
                        foreach ($ExtraFile in $ExtraFiles) {
                            Write-Host "$OSBuilderContent\$ExtraFile" -ForegroundColor DarkGray
                            robocopy "$OSBuilderContent\$ExtraFile" "$MountDirectory" *.* /e /ndl /xx /b /np /ts /tee /r:0 /w:0 /Log+:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ExtraFiles.log" | Out-Null
                        }
                    }
                    
                    #===================================================================================================
                    Write-Verbose '19.1.11 Start Layout'
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: Start Layout" -ForegroundColor Green
                    if ($StartLayoutXML -and $OSMajorVersion -eq 10) {
                        Write-Host "$OSBuilderContent\$StartLayoutXML" -ForegroundColor DarkGray
                        Copy-Item -Path "$OSBuilderContent\$StartLayoutXML" -Destination "$MountDirectory\Users\Default\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml" -Recurse -Force | Out-Null
                    }

                    #===================================================================================================
                    Write-Verbose '19.1.11 Unattend.xml'
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: Unattend.xml" -ForegroundColor Green
                    if ($UnattendXML -and $OSMajorVersion -eq 10) {
                        Write-Host "$OSBuilderContent\$UnattendXML" -ForegroundColor DarkGray
                        if (!(Test-Path "$MountDirectory\Windows\Panther")) {New-Item -Path "$MountDirectory\Windows\Panther" -ItemType Directory -Force | Out-Null}
                        Copy-Item -Path "$OSBuilderContent\$UnattendXML" -Destination "$MountDirectory\Windows\Panther\Unattend.xml" -Force
                        Use-WindowsUnattend -UnattendPath "$OSBuilderContent\$UnattendXML" -Path "$MountDirectory" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Use-WindowsUnattend.log" | Out-Null
                    }
                    
                    #===================================================================================================
                    Write-Verbose '19.1.1 PowerShell Scripts'
                    #===================================================================================================
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Host "Install.wim: PowerShell Scripts" -ForegroundColor Green
                    foreach ($PSScript in $Scripts) {
                        if (Test-Path "$OSBuilderContent\$PSScript") {
                            Write-Host "PowerShell Script: $OSBuilderContent\$PSScript" -ForegroundColor Green
                            Invoke-Expression "& '$OSBuilderContent\$PSScript'"
                        }
                    }
                }
                
                #===================================================================================================
                Write-Verbose '19.1.1 Copy-OSBAutoExtraFiles'
                #===================================================================================================
                Write-Host '========================================================================================' -ForegroundColor DarkGray
                Copy-OSBAutoExtraFiles -OSMediaPath "$WorkingPath" -MountDirectory "$MountDirectory"

                #===================================================================================================
                Write-Verbose '19.1.1 Copy-OSBSessions'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                Copy-OSBSessions -OSMediaPath "$WorkingPath" -MountDirectory "$MountDirectory"

                #===================================================================================================
                Write-Verbose '19.1.1 Export-OSBInstallWimInventory'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                Export-OSBInstallWimInventory -OSMediaPath "$WorkingPath" -MountDirectory "$MountDirectory"

                #===================================================================================================
                Write-Verbose '19.1.1 Install.wim: Dismount'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Host "Install.wim: Dismount from $MountDirectory" -ForegroundColor Green

                if ($PromptBeforeDismount.IsPresent){[void](Read-Host 'Press Enter to Continue')}

                $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dismount-WindowsImage.log"
                Write-Verbose "$CurrentLog"
                If ($Repair.IsPresent) {
                    Dismount-WindowsImage -Path "$MountDirectory" -Discard -LogPath "$CurrentLog" | Out-Null
                } else {
                    Dismount-WindowsImage -Path "$MountDirectory" -Save -LogPath "$CurrentLog" | Out-Null
                }

                #===================================================================================================
                Write-Verbose '19.1.1 Install.wim: Export'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Host "Install.wim: Export to $OS\sources\install.wim" -ForegroundColor Green
                $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage.log"
                Write-Verbose "$CurrentLog"
                Export-WindowsImage -SourceImagePath "$WimTemp\install.wim" -SourceIndex 1 -DestinationImagePath "$OS\sources\install.wim" -LogPath "$CurrentLog" | Out-Null

                #===================================================================================================
                Write-Verbose '19.1.1 Install.wim: Export Configuration'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Host "Install.wim: Export Configuration to $WorkingPath\WindowsImage.txt" -ForegroundColor Green
                $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.1*") {
                    Write-Verbose '========== Windows 6.1'
                    $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"
                
                #===================================================================================================
                Write-Verbose '19.1.1 Install.wim: Export Content'
                #===================================================================================================
                #Write-Host '========================================================================================' -ForegroundColor DarkGray
                Write-Host "Install.wim: Export Content to $Info\Get-WindowsImageContent.txt" -ForegroundColor Green
                Get-WindowsImageContent -ImagePath "$OS\Sources\install.wim" -Index 1 | Out-File "$Info\Get-WindowsImageContent.txt"

                #===================================================================================================
                Write-Verbose '19.1.1 UBR Validation'
                #===================================================================================================
                if (!($Repair.IsPresent)) {
                    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('mmss'))
                        Write-Warning 'Could not determine a UBR'
                    }
                }

                #===================================================================================================
                Write-Verbose '19.1.1 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}

                #===================================================================================================
                Write-Verbose '19.1.1 Set New Name'
                #===================================================================================================
                $OSImageName = $($GetWindowsImage.ImageName)
                $OSImageName = $OSImageName -replace '\(', ''
                $OSImageName = $OSImageName -replace '\)', ''

                $OSArchitecture = $($GetWindowsImage.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'}

                $OSBuild = $($GetWindowsImage.Build)
                $OSVersionNumber = $null
                if (Test-Path "$Info\xml\CurrentVersion.xml") {
                    $RegCurrentVersion = Import-Clixml -Path "$Info\xml\CurrentVersion.xml"
                    $OSVersionNumber = $($RegCurrentVersion.ReleaseId)
                }

                if ($OSBuild -eq 7601) {$OSVersionNumber = 7601}
                if ($OSBuild -eq 10240) {$OSVersionNumber = 1507}
                if ($OSBuild -eq 14393) {$OSVersionNumber = 1607}
                if ($OSBuild -eq 15063) {$OSVersionNumber = 1703}
                if ($OSBuild -eq 16299) {$OSVersionNumber = 1709}
                if ($OSBuild -eq 17134) {$OSVersionNumber = 1803}
                if ($OSBuild -eq 17763) {$OSVersionNumber = 1809}

                if ($null -eq $OSVersionNumber) {
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Write-Warning "Windows Image Build $OSBuild is not automatically recognized"
                    Write-Warning "Check for an updated version of OSBuilder"
                    if ($WorkingName -like "build*") {$NewOSMediaName = "$OSImageName $OSArchitecture $UBR"}
                } elseif ($OSBuild -eq 7601) {
                    if ($WorkingName -like "build*") {$NewOSMediaName = "$OSImageName $OSArchitecture SP1 $UBR"}
                } else {
                    if ($WorkingName -like "build*") {$NewOSMediaName = "$OSImageName $OSArchitecture $OSVersionNumber $UBR"}
                }

                $OSLanguages = $($GetWindowsImage.Languages)

                $NewOSMediaName = "$NewOSMediaName $OSLanguages"
                if ($($OSLanguages.count) -eq 1) {$NewOSMediaName = $NewOSMediaName.replace(' en-US','')}

                if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {
                    if ($CustomName) {$NewOSMediaName = "$CustomName $UBR"}
                }
                
                if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia') {$NewOSMediaPath = "$OSBuilderOSMedia\$NewOSMediaName"}
                if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {$NewOSMediaPath = "$OSBuilderOSBuilds\$NewOSMediaName"}

                #===================================================================================================
                Write-Verbose '19.1.1 Rename Build Directory'
                #===================================================================================================
                if (!($Repair.IsPresent)) {
                    if (Test-Path $NewOSMediaPath) {
                        $mmss = $((Get-Date).ToString('mmss'))
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        Write-Warning 'Trying to rename the Build directory, but it already exists'
                        Write-Warning "Appending $mmss to the directory Name"
                        Write-Host '========================================================================================' -ForegroundColor DarkGray
                        $NewOSMediaName = "$NewOSMediaName $mmss"
                        $NewOSMediaPath = "$OSBuilderOSMedia\$NewOSMediaName"
                    }
                }

                #===================================================================================================
                Write-Verbose '19.1.1 Export Variables.xml'
                #===================================================================================================
                Get-Variable | Select-Object -Property Name, Value | Export-Clixml "$Info\xml\Variables.xml"
                Get-Variable | Select-Object -Property Name, Value | ConvertTo-Json | Out-File "$Info\json\Variables.json"

                #===================================================================================================
                Write-Verbose '19.1.1 New-OSBMediaISO'
                #===================================================================================================
                if ($CreateISO.IsPresent) {
                    New-OSBMediaISO -FullName "$WorkingPath"
                }

                #===================================================================================================
                Write-Verbose '19.1.1 Show-OSBMediaInfo'
                #===================================================================================================
                if ($ShowMediaInfo.IsPresent) {
                    Show-OSBMediaInfo -FullName "$WorkingPath"
                }

                #===================================================================================================
                Write-Verbose '19.1.1 Stop Transcript'
                #===================================================================================================
                if ($Repair.IsPresent) {
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Stop-Transcript
                }
                else {
                    Write-Host "Media: Renaming ""$WorkingPath"" to ""$NewOSMediaName""" -ForegroundColor Green
                    Write-Host '========================================================================================' -ForegroundColor DarkGray
                    Stop-Transcript
                    Rename-Item -Path "$WorkingPath" -NewName "$NewOSMediaName" -ErrorAction Stop
                }
            }
        }
    }

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