?param([string]$ErrFile,[string]$ScriptPath="",[string[]]$Tags=@()) $ErrorActionPreference='Stop' $root="\\DS-918\chatgpt\ChatGPT-Gouvernance-Projets\_registry" $inbox=Join-Path $root "updates\inbox\kb" if(!(Test-Path $inbox)){ New-Item -ItemType Directory -Force -Path $inbox|Out-Null } $err = "" if($ErrFile -and (Test-Path $ErrFile)){ $err = Get-Content -LiteralPath $ErrFile -Raw } elseif($global:error.Count -gt 0){ $err = ($error[0] | Out-String) } $title="" $first = ($err -split "`r?`n" | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -First 1) if($first){ $title=$first.Trim() } elseif($ScriptPath){ $title="Error in "+[IO.Path]::GetFileName($ScriptPath) } else { $title="Unclassified script error" } $stamp = Get-Date -Format 'yyyyMMdd_HHmmss' $out = Join-Path $inbox ("AUTO_"+$stamp+".txt") $tags = @("autodraft") + $Tags $lines = @( "Title: "+$title, "Blocking: true", "RootCause: "+$err.Substring(0,[Math]::Min(500,[Math]::Max(0,$err.Length))).Replace([char]0x00,' '), "Workaround: ", "Fix: ", "Tags: "+($tags -join ','), "SeenInThreads: "+(Get-Date -Format 'yyyy-MM-dd') ) [IO.File]::WriteAllText($out, ($lines -join "`r`n"), (New-Object Text.UTF8Encoding($true))) Write-Host "[AUTO] draft -> $out"