# gov_profile_launcher_v1.9.ps1 # Purpose: Delegate to the highest available gov_profile_launcher_vX.Y.ps1 (excluding v1.9 itself) Get-ChildItem -Path $pwd -Recurse -File | ForEach-Object { Select-String ', no aliases. UTF-8 with BOM. -Path $_.FullName } # Behavior: finds best candidate by [version] + LastWriteTime, launches it with same args, prints OK/NOK without calling 'exit'. try { [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding } catch {} # --- Resolve paths (script folder -> repo root -> scripts dir) --- $Here = $PSScriptRoot if (-not $Here) { $Here = Split-Path -Parent $MyInvocation.MyCommand.Path } $Root = Split-Path -Parent $Here $ScriptsDir = Join-Path -Path $Root -ChildPath 'scripts' # --- Helper: extract [version] from name like gov_profile_launcher_v1.2.3.ps1 (no non-capturing groups) --- function Get-LauncherVersion([string]$Name) { $m = [regex]::Match($Name, '_v([0-9]+(\.[0-9]+)*)\.ps1$') if ($m.Success) { try { return [version]$m.Groups[1].Value } catch { return [version]'0.0' } } return [version]'0.0' } # --- Find candidates (exclude self = v1.9 name) --- $Candidates = @() try { $Candidates = Get-ChildItem -LiteralPath $ScriptsDir -Filter 'gov_profile_launcher_v*.ps1' -File -ErrorAction SilentlyContinue | Where-Object { $_.Name -ne 'gov_profile_launcher_v1.9.ps1' } } catch { Write-Host ('[NOK] scripts directory inaccessible -> {0}' -f $ScriptsDir) $Candidates = @() } if (-not $Candidates -or $Candidates.Count -eq 0) { Write-Host '[NOK] Aucun launcher versionné trouvé (hors v1.9).' return } # --- Pick the best candidate: highest version, then most recent write time --- $Best = $Candidates | Sort-Object ` @{ Expression = { Get-LauncherVersion $_.Name }; Descending = $true }, ` @{ Expression = { $_.LastWriteTime }; Descending = $true } | Select-Object -First 1 Write-Host ("[INFO] Délégation vers: {0}" -f $Best.FullName) # --- Delegate (same args), preserve $LASTEXITCODE but do not call 'exit' --- try { & powershell -NoProfile -ExecutionPolicy Bypass -File $Best.FullName @args $code = $LASTEXITCODE if ($code -is [int]) { if ($code -eq 0) { Write-Host ('[OK] Délégation terminée (code={0})' -f $code) } else { Write-Host ('[NOK] Délégation terminée avec code non nul (code={0})' -f $code) } } else { Write-Host '[INFO] Délégation terminée (pas de code numérique explicite)' } } catch { Write-Host ('[NOK] Exception lors de la délégation -> {0}' -f $_.Exception.Message) }