private/Select-BuildOSDeployBootWinPEStartupProfiles.ps1

#Requires -PSEdition Core

function Select-BuildOSDeployBootWinPEStartupProfiles {
    <#
    .SYNOPSIS
        Selects WinPEStartup profiles for an OSDeploy Boot build
 
    .DESCRIPTION
        Enumerates JSON files from the OSDeploy module, available OSDCloud and OSD module
        core\winpestartup-profiles directories, and the OSDeploy Boot-Assets
        winpestartup-profiles directory. All discovered files are displayed in an
        Out-GridView multi-selection picker. Files with the same name in different source
        directories are displayed as separate entries.
 
        The caller uses selected profiles as build content. This function does not copy
        or modify the profiles. Canceling the picker returns no object.
 
    .EXAMPLE
        PS> Select-BuildOSDeployBootWinPEStartupProfiles
 
        Displays all discovered WinPEStartup profile files for multi-selection.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        System.Management.Automation.PSCustomObject[]. Returns selected objects with Name,
        FullName, and LastWriteTime properties, or no object when none are selected.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 1.0.0
        Date: 2026-08-28
 
        Change Summary:
            - Initial version.
 
        OSDCloud and OSD profile roots are searched only when their module path commands are available.
 
    .LINK
        Build-OSDeployBoot
    #>

    [CmdletBinding()]
    param ()

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

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

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

    $OSDRepoPaths += Join-Path $Script:OSDeployBootAssetsPath 'winpestartup-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-HostDateTimeDarkGray 'Select WinPEStartup Profiles to add to this boot image (Cancel to skip)'
        $selected = $profileItems |
            Out-GridView -PassThru -Title 'Select WinPEStartup Profiles to add to this boot image (Cancel to skip)'

        return $selected
    }

    return $null
}