functions/common/Convert-ToUtf8Bom.ps1

function Convert-ToUtf8Bom {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [Alias("FullName")]
        [string[]] $Path
    )

    process {
        if ($Path.Count -eq 1 -and $Path[0] -eq '.') {
            $Path[0] = (Resolve-Path -Path '.').Path
        }
        
        foreach ($inputPath in $Path) {
            if (Test-Path $inputPath) {
                $files = @()

                if ((Get-Item $inputPath).PSIsContainer) {
                    $files += Get-ChildItem -Path $inputPath -Recurse -Filter *.ps1
                } else {
                    $files += Get-Item -Path $inputPath
                }

                foreach ($file in $files) {
                    try {
                        $content = Get-Content -Path $file.FullName -Raw
                        $utf8BomEncoding = New-Object System.Text.UTF8Encoding($true)
                        [System.IO.File]::WriteAllText($file.FullName, $content, $utf8BomEncoding)

                        Write-Host "✔ Konvertiert: $($file.FullName)" -ForegroundColor Green
                    } catch {
                        Write-Warning "Fehler bei Datei $($file.FullName): $_"
                    }
                }
            } else {
                Write-Warning "Pfad nicht gefunden: $inputPath"
            }
        }
    }
}