Libraries/Bootloader/Includes/Bootloader.BCD.psm1

<#
.SYNOPSIS
Search for a bcd configuration
 
.DESCRIPTION
Search into local partition for a bcd.cfg file.
Default search for a "bcd.cfg" file. If config name is overriden, use -Filename to search for custom filename.
 
.EXAMPLE
Find-OSBootloaderBCDCfg -Path "/boot"
 
.EXAMPLE
Find-OSBootloaderBCDCfg -Path "/boot" -Filename "mybcd.cfg"
 
.NOTES
General notes
#>

function Find-OSBootloaderBCDCfg {
    [CmdletBinding()]
    [OutputType([String])]
    Param (
        # Path to start search
        [Parameter(Mandatory = $true, ValueFromPipeLine = $true)][string]$Path,
        # Custom filename to search for
        [Parameter(Mandatory = $false, ValueFromPipeLine = $false)][string]$Filename = "BCD"
    )
    Begin {
        Write-EnterFunction
    }

    Process {
        $bcdcfg = Get-ChildItem -Path $Path/EFI/Microsoft/Boot $Filename -Recurse
        return ${bcdcfg}?.fullname
    }

    End {
        Write-LeaveFunction
    }
}

function Set-OSBootloaderBCDDefaultBoot {
    [CmdletBinding()]
    [OutputType([System.Boolean])]
    Param (
        [Alias('ConfigFile')]
        [Parameter(Mandatory = $false, ValueFromPipeLine = $false)][string]$BCDCfg = (Find-OSBootloaderbcdCfg -Path "/EFI"),
        [Parameter(Mandatory = $true, ValueFromPipeLine = $false)][string]$label
    )
    Begin {
        Write-EnterFunction
    }

    Process {
        $bcd = Get-BCD
        $bcdEntry = $bcd | Where-Object { $_.label -eq "$label" }
        Set-BCDDisplayOrder -id $bcdEntry.id -AddFirst
        return $?
    }

    End {
        Write-LeaveFunction
    }
}