Private/OSB-Drivers.ps1

function OSB-Drivers {
    [CmdletBinding()]
    PARAM ()
    Write-Host '========================================================================================' -ForegroundColor DarkGray
    Write-Host "Install.wim: Task 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-Task-Driver.log"
            } else {
                Add-WindowsDriver -Driver "$OSBuilderContent\$Driver" -Recurse -Path "$MountDirectory" -ForceUnsigned -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Task-Driver.log" | Out-Null
            }
        }
    } else {
        Write-Host "No Task Drivers were processed" -ForegroundColor DarkGray
    }
    
    Write-Host '========================================================================================' -ForegroundColor DarkGray
    Write-Host "Install.wim: Template Drivers"    -ForegroundColor Green

    $AOSBDrivers = @()
    $AOSBDrivers = Get-ChildItem ("$OSBuilderTemplates\Drivers\AutoApply\Global\*","$OSBuilderTemplates\Drivers\AutoApply\Global $OSArchitecture\*") | Where-Object {$_.PSIsContainer -eq $true} | Select-Object -Property FullName
    if ($OSVersionNumber -eq 7601) {
        [array]$AOSBDrivers += Get-ChildItem ("$OSBuilderTemplates\Drivers\AutoApply\Windows 7\*","$OSBuilderTemplates\Drivers\AutoApply\Windows 7 $OSArchitecture\*") | Where-Object {$_.PSIsContainer -eq $true} | Select-Object -Property FullName
    } else {
        if ($OSInstallationType -eq 'Client') {
            [array]$AOSBDrivers += Get-ChildItem ("$OSBuilderTemplates\Drivers\AutoApply\Windows 10\*","$OSBuilderTemplates\Drivers\AutoApply\Windows 10 $OSArchitecture\*") | Where-Object {$_.PSIsContainer -eq $true} | Select-Object -Property FullName
            #[array]$AOSBDrivers += Get-ChildItem ("$OSBuilderTemplates\Drivers\AutoApply\Windows 10\*","$OSBuilderTemplates\Drivers\AutoApply\Windows 10 $OSArchitecture\*","$OSBuilderTemplates\Drivers\AutoApply\Windows 10 $OSArchitecture $OSVersionNumber\*") | Where-Object {$_.PSIsContainer -eq $true} | Select-Object -Property FullName
        } else {
            [array]$AOSBDrivers += Get-ChildItem "$OSBuilderTemplates\Drivers\AutoApply\Windows Server\*" | Where-Object {$_.PSIsContainer -eq $true} | Select-Object -Property FullName
            #[array]$AOSBDrivers += Get-ChildItem ("$OSBuilderTemplates\Drivers\AutoApply\Windows Server\*","$OSBuilderTemplates\Drivers\AutoApply\Windows Server $OSVersionNumber\*") | Where-Object {$_.PSIsContainer -eq $true} | Select-Object -Property FullName
        }
    }

    if ($SkipTemplates) {$AOSBDrivers = @()}

    if ($AOSBDrivers) {
        foreach ($Driver in $AOSBDrivers) {
            Write-Host "$($Driver.FullName)" -ForegroundColor DarkGray
            if ($OSMajorVersion -eq 6) {
                dism /Image:"$MountDirectory" /Add-Driver /Driver:"$($Driver.FullName)" /Recurse /ForceUnsigned /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DISM-Template-Driver.log"
            } else {
                Add-WindowsDriver -Driver "$($Driver.FullName)" -Recurse -Path "$MountDirectory" -ForceUnsigned -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Template-Driver.log" | Out-Null
            }
        }
    } else {
        Write-Host "No Template Drivers were processed" -ForegroundColor DarkGray
    }
}

function OSB-WinPE-Drivers {
    [CmdletBinding()]
    PARAM ()
    Write-Host '========================================================================================' -ForegroundColor DarkGray
    Write-Host "WinPE: Task WinPE Drivers" -ForegroundColor Green
    if ($WinPEDrivers) {
        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"
                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"
                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 "$MountWinPE" -Driver "$OSBuilderContent\$WinPEDriver" -Recurse -ForceUnsigned -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsDriver-WinPE.log" | Out-Null
                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
                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
            }
        }
    } else {
        Write-Host "No Task WinPE Drivers were processed" -ForegroundColor DarkGray
    }

<# Write-Host '========================================================================================' -ForegroundColor DarkGray
    Write-Host "WinPE: Template WinPE Drivers" -ForegroundColor Green
 
    $AOSBDriversWinPE = @()
    $AOSBDriversWinPE = Get-ChildItem ("$OSBuilderTemplates\DriversWinPE\AutoApply\Global\*","$OSBuilderTemplates\DriversWinPE\AutoApply\Global $OSArchitecture\*") | Where-Object {$_.PSIsContainer -eq $true} | Select-Object -Property FullName
    if ($OSVersionNumber -eq 7601) {
        [array]$AOSBDriversWinPE += Get-ChildItem ("$OSBuilderTemplates\DriversWinPE\AutoApply\WinPE 3\*","$OSBuilderTemplates\DriversWinPE\AutoApply\WinPE 3 $OSArchitecture\*") | Where-Object {$_.PSIsContainer -eq $true} | Select-Object -Property FullName
    } else {
        if ($OSInstallationType -eq 'Client') {
            [array]$AOSBDriversWinPE += Get-ChildItem ("$OSBuilderTemplates\DriversWinPE\AutoApply\WinPE 10\*","$OSBuilderTemplates\DriversWinPE\AutoApply\WinPE 10 $OSArchitecture\*","$OSBuilderTemplates\DriversWinPE\AutoApply\WinPE 10 $OSArchitecture $OSVersionNumber\*") | Where-Object {$_.PSIsContainer -eq $true} | Select-Object -Property FullName
        } else {
            [array]$AOSBDriversWinPE += Get-ChildItem ("$OSBuilderTemplates\DriversWinPE\AutoApply\WinPE Server\*","$OSBuilderTemplates\DriversWinPE\AutoApply\WinPE Server $OSVersionNumber\*") | Where-Object {$_.PSIsContainer -eq $true} | Select-Object -Property FullName
        }
    } #>

}