# DEV-ONESHOT — exécute ton code dans GOV Shell (Bypass + autolog KB) # ⚠️ Si ton dev utilise des variables définies ici, reste dans le MÊME shell. $ErrorActionPreference = 'Stop' # Racines et outils $GOV_ROOT = '\\DS-918\chatgpt\ChatGPT-Gouvernance-Projets\_registry' $RUN_CMD = Join-Path $GOV_ROOT 'scripts\run_in_govshell.cmd' $KB_QUICK = Join-Path $GOV_ROOT 'scripts\kb_quicklog_and_sync_v1.2.1.ps1' $KB_BULK = Join-Path $GOV_ROOT 'scripts\kb_bulk_ingest_v1.2.1.ps1' # Replis si 1.2.1 pas encore dispo if(-not (Test-Path $KB_QUICK)){ $KB_QUICK = Join-Path $GOV_ROOT 'scripts\kb_quicklog_and_sync_v1.2.ps1' } if(-not (Test-Path $KB_BULK )){ $KB_BULK = Join-Path $GOV_ROOT 'scripts\kb_bulk_ingest_v1.2.ps1' } # Option: ingestion immédiate après exécution (sinon le BULK tournera plus tard) $KB_COMMIT_NOW = $false # passe à $true si tu veux “ingérer et archiver” tout de suite # Ton code de test/correction ici (PS 5.1 compatible) $code = @' # -- Ton code de test ici -- Write-Host "[DEMO] Hello depuis le script de test" # Pour déclencher un autolog KB (facultatif), force une petite erreur contrôlée : # Get-Item \\DS-918\__chemin_qui_nexiste_pas__ | Out-Null '@ # Sauvegarde en UTF-8 BOM et exécution via GOV Shell (Bypass + archiviste chargé) $stage = 'C:\Temp_Gouvernance' if(!(Test-Path $stage)){ New-Item -ItemType Directory -Force -Path $stage | Out-Null } $tmp = Join-Path $stage ("dev_oneshot_{0}.ps1" -f (Get-Date -Format 'yyyyMMdd_HHmmss')) # PS 5.1-safe: pas de ternaire, UTF-8 BOM explicite $Utf8BOM = New-Object Text.UTF8Encoding($true) [IO.File]::WriteAllText($tmp, $code, $Utf8BOM) # Garde: wrappers .cmd appellent powershell.exe -ExecutionPolicy Bypass (OK avec AllSigned) if(-not (Test-Path $RUN_CMD)){ Write-Warning "[GOV] run_in_govshell.cmd introuvable: $RUN_CMD" }else{ & $RUN_CMD $tmp } # (Optionnel) Ingestion immédiate en KB pour vider la boîte d'entrée et pousser dans le bootpack if($KB_COMMIT_NOW){ $ps = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" if(Test-Path $KB_BULK){ & $ps -NoProfile -ExecutionPolicy Bypass -File $KB_BULK -Execute -After Move } elseif(Test-Path $KB_QUICK) { # Mode “quicklog” unitaire si le BULK n’est pas dispo $inbox = Join-Path $GOV_ROOT 'updates\inbox\kb' $auto = Get-ChildItem -LiteralPath $inbox -Filter 'AUTO_*.txt' -File -ErrorAction SilentlyContinue | Select-Object -First 1 if($auto){ & $ps -NoProfile -ExecutionPolicy Bypass -File $KB_QUICK -FromFile $auto.FullName -Execute } } }