private/BootMedia/Steps/Select-OSDeployCoreBuildScript.ps1

#Requires -PSEdition Core

function Select-OSDeployCoreBuildScript {
    <#
    .SYNOPSIS
        Displays WinPE build scripts in an Out-GridView picker.
 
    .DESCRIPTION
        Enumerates scripts from the OSDRe directories for winpe-appscript,
        winpe-script, and media-script types, then presents them in an Out-GridView
        for multi-selection.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Change Summary:
        - Added core\OSDRe as a second search path alongside Repository.
    #>

    [CmdletBinding()]
    param ()

    $OSDRePath = Join-Path $Script:OSDeployModuleBase 'core' 'OSDRe'

    $searchRoots = @($Script:OSDeployCoreRepositoryPath, $OSDRePath)

    $osdCloudBase = if (Get-Command -Name 'Get-OSDCloudModulePath' -ErrorAction SilentlyContinue) { Get-OSDCloudModulePath }
    if ($osdCloudBase) {
        $searchRoots += Join-Path $osdCloudBase 'core' 'OSDRe'
    }

    $osdBase = if (Get-Command -Name 'Get-OSDModulePath' -ErrorAction SilentlyContinue) { Get-OSDModulePath }
    if ($osdBase) {
        $searchRoots += Join-Path $osdBase 'core' 'OSDRe'
    }

    $scriptTypes = @('winpe-appscript', 'winpe-script', 'media-script')
    $scriptItems = @()

    foreach ($root in $searchRoots) {
        foreach ($type in $scriptTypes) {
            $typePath = Join-Path $root $type
            if (Test-Path -LiteralPath $typePath) {
                $scriptItems += Get-ChildItem -LiteralPath $typePath -Filter '*.ps1' -File -Recurse -Depth 1 -ErrorAction SilentlyContinue |
                    Select-Object @{Name = 'Type'; Expression = { $type } },
                        Name,
                        FullName,
                        LastWriteTime
            }
        }
    }

    if ($scriptItems -and $scriptItems.Count -gt 0) {
        Write-OSDeployCoreProgress 'Select Scripts to run during the build (Cancel to skip)'
        $selected = $scriptItems |
            Out-GridView -PassThru -Title 'Select Scripts to run during the build (Cancel to skip)'

        return $selected
    }

    return $null
}