private/BootMedia/Steps/Select-OSDeployCoreBuildStartupProfile.ps1

#Requires -PSEdition Core

function Select-OSDeployCoreBuildStartupProfile {
    <#
    .SYNOPSIS
        Displays WinPE Startup profiles in an Out-GridView picker.
 
    .DESCRIPTION
        Enumerates JSON profiles from the core\OSDRepo\winpe-profiles directory and
        presents them in an Out-GridView for multi-selection. Selected profiles will be
        copied into the mounted WinPE at WinPEStartup\Profiles during the build.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Change Summary:
        - Initial version.
 
    Dependencies:
      Module Functions: Write-OSDeployCoreProgress
      External Modules: OSDCloud (Get-OSDCloudModulePath); OSD (Get-OSDModulePath)
      Windows Features: Windows ADK WinPE Addon
    #>

    [CmdletBinding()]
    param ()

    $OSDRepoPaths = @(Join-Path $Script:OSDeployModuleBase 'core' 'OSDRepo' 'winpe-profiles')

    $osdCloudBase = if (Get-Command -Name 'Get-OSDCloudModulePath' -ErrorAction SilentlyContinue) { Get-OSDCloudModulePath }
    if ($osdCloudBase) {
        $OSDRepoPaths += Join-Path $osdCloudBase 'core' 'OSDRepo' 'winpe-profiles'
    }

    $osdBase = if (Get-Command -Name 'Get-OSDModulePath' -ErrorAction SilentlyContinue) { Get-OSDModulePath }
    if ($osdBase) {
        $OSDRepoPaths += Join-Path $osdBase 'core' 'OSDRepo' 'winpe-profiles'
    }

    $OSDRepoPaths += Join-Path $Script:OSDeployOSDRepoPath 'winpe-profiles'

    $profileItems = @()
    foreach ($OSDRepoPath in $OSDRepoPaths) {
        if (Test-Path -LiteralPath $OSDRepoPath) {
            $profileItems += Get-ChildItem -LiteralPath $OSDRepoPath -Filter '*.json' -File -ErrorAction SilentlyContinue |
                Select-Object Name, FullName, LastWriteTime
        }
    }

    if ($profileItems -and $profileItems.Count -gt 0) {
        Write-OSDeployCoreProgress 'Select WinPE Startup Profiles to copy (Cancel to skip)'
        $selected = $profileItems |
            Out-GridView -PassThru -Title 'Select WinPE Startup Profiles to copy (Cancel to skip)'

        return $selected
    }

    return $null
}