functions/filesystem/Get-FirstItem.ps1

function Get-FirstItem {
<#
.SYNOPSIS
Finds the first matching file in a directory and its subdirectories.
 
.DESCRIPTION
Searches recursively starting from a specified path for the first file that matches the given filter.
Returns the first match found as a FileInfo object. Useful for dynamically locating script files in flexible folder structures.
 
.PARAMETER Path
The base directory where the search starts.
 
.PARAMETER Filter
The file name or pattern to search for (e.g., 'Invoke-MyFunction.ps1').
 
.OUTPUTS
System.IO.FileInfo
 
.EXAMPLE
Get-FirstItem -Path $PSScriptRoot -Filter 'Invoke-MyFunction.ps1'
 
Searches for the file 'Invoke-MyFunction.ps1' starting from the current script's directory and returns the first match.
 
.NOTES
Author: Jascha Vincke
#>


    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [string]$Path,

        [Parameter(Mandatory)]
        [string]$Filter
    )

    # Nur Dateien mit dem gegebenen Namen rekursiv suchen
    $item = Get-ChildItem -Path $Path -Filter $Filter -File -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1

    return $item
}