# gov_profile_launcher_v1.10.ps1 # Purpose: Delegate to the highest available gov_profile_launcher_vX.Y.ps1 (excluding self), PS 5.1 strict. # Guards: Validate $Root; avoid recursion; preserve args. param( [string]$Root='\\DS-918\chatgpt\ChatGPT-Gouvernance-Projets\_registry' ) try { [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding } catch {} if([string]::IsNullOrWhiteSpace($Root)){ Write-Host "[NOK] Root vide."; exit 2 } $ScriptsDir = Join-Path -Path $Root -ChildPath 'scripts' function Get-Version([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 in $ScriptsDir $candidates = Get-ChildItem -LiteralPath $ScriptsDir -Filter 'gov_profile_launcher_v*.ps1' -File -ErrorAction SilentlyContinue if(-not $candidates){ Write-Host "[NOK] Aucun candidat trouvé dans $ScriptsDir"; exit 3 } $me = Split-Path -Leaf $MyInvocation.MyCommand.Path $best = $null; $bestV=[version]"0.0"; $self = $me.ToLowerInvariant() foreach($c in $candidates){ $leaf = $c.Name.ToLowerInvariant() if($leaf -eq $self){ continue } # avoid calling self $v = Get-Version $c.Name if($v -gt $bestV){ $bestV = $v; $best = $c } } if($null -eq $best){ Write-Host "[NOK] Aucun candidat supérieur à $me"; exit 4 } # Build argument list (preserve all original args as-is) $argsList = @() foreach($a in $args){ $argsList += $a } Write-Host ("[INFO] Delegating to {0}" -f $best.FullName) & $best.FullName @argsList # propagate exit code naturally