private/Select-BuildOSDeployBootWinpeStartupCore.ps1

#Requires -PSEdition Core

function Select-BuildOSDeployBootWinpeStartupCore {
    <#
    .SYNOPSIS
        Selects WinpeStartup Core folders for an OSDeploy Boot build
 
    .DESCRIPTION
        Enumerates the immediate child directories of the OSDeploy Boot-Assets
        winpestartup-core directory. Each immediate child directory is a core folder. All
        discovered directories except main are displayed in an Out-GridView
        multi-selection picker. The main directory is included automatically when present.
 
        The caller uses selected folders as build content. This function does not copy
        or modify the folders. Canceling the picker skips optional folders but still
        returns main when present.
 
    .EXAMPLE
        PS> Select-BuildOSDeployBootWinpeStartupCore
 
        Includes main automatically and displays optional Core directories 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. The main object is returned first when
        present, even when the picker is canceled. Returns no object when main is absent
        and no optional folders are selected.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 1.0.0
        Date: 2026-10-05
 
        Change Summary:
            - Initial version.
 
    .LINK
        Build-OSDeployBoot
    #>

    [CmdletBinding()]
    param ()

    $WinpeStartupCorePath = Join-Path $Script:OSDeployBootAssetsPath 'winpestartup-core'

    $coreItems = @()
    if (Test-Path -LiteralPath $WinpeStartupCorePath -PathType Container) {
        $coreItems = @(
            Get-ChildItem -LiteralPath $WinpeStartupCorePath -Directory -ErrorAction SilentlyContinue |
                Select-Object Name, FullName, LastWriteTime | Sort-Object Name
        )
    }

    $mainItems = @($coreItems | Where-Object Name -EQ 'main')
    $optionalItems = @($coreItems | Where-Object Name -NE 'main')
    $selected = @()
    if ($optionalItems.Count -gt 0) {
        Write-HostDateTimeDarkGray 'Select WinpeStartup Core folders to add to this boot image (Cancel to skip)'
        $selected = $optionalItems |
            Out-GridView -PassThru -Title 'Select WinpeStartup Core folders to add to this boot image (Cancel to skip)'
    }

    return @($mainItems) + @($selected | Where-Object { $_ })
}