@@ -17,49 +17,52 @@ $depts = (
1717 ).organisationUnitGroups[0 ].organisationUnits.code | Where-Object - FilterScript { $_ -match $SiteCodeFilter } | Sort-Object
1818
1919$wd = Get-Location
20- Set-Location - LiteralPath $PSScriptRoot
20+ try {
21+ Set-Location - LiteralPath $PSScriptRoot
2122
22- foreach ($site in $depts ) {
23- Write-Host " Generating validation report for $site ..."
24- $outFile = " $ ( [datetime ]::Now.ToString(' yyyy-MM-dd_HHmmss' )) _NeoIPC-Surveillance-Validation-Report_$ ( $site ) .$ ( $Language ) .pdf"
25- $skipRest = $false
26- $errorLine = ' '
27- $isError = $false
28- quarto render -- profile $Language - P " language:$Language " - P " token:../../../token.txt" - P " departmentFilter:$ ( $site ) " - o $outFile 2>&1 | ForEach-Object - Process {
29- if ($skipRest ) {
30- return
31- }
32- $s = " $_ "
33- if ($s -eq ' System.Management.Automation.RemoteException' ) {
34- $s = ' '
35- }
36- if ($isError ) {
37- if ($s -eq ' ! No problem detected' ) {
38- Write-Host " No problem detected." - ForegroundColor DarkYellow
39- $skipRest = $true
23+ foreach ($site in $depts ) {
24+ Write-Host " Generating validation report for $site ..."
25+ $outFile = " $ ( [datetime ]::Now.ToString(' yyyy-MM-dd_HHmmss' )) _NeoIPC-Surveillance-Validation-Report_$ ( $site ) .$ ( $Language ) .pdf"
26+ $skipRest = $false
27+ $errorLine = ' '
28+ $isError = $false
29+ quarto render -- profile $Language - P " language:$Language " - P " token:../../../token.txt" - P " departmentFilter:$ ( $site ) " - o $outFile 2>&1 | ForEach-Object - Process {
30+ if ($skipRest ) {
31+ return
4032 }
41- else {
42- if ($errorLine.Length -gt 0 ) {
43- Write-Error - Message $errorLine
44- $errorLine = ' '
33+ $s = " $_ "
34+ if ($s -eq ' System.Management.Automation.RemoteException' ) {
35+ $s = ' '
36+ }
37+ if ($isError ) {
38+ if ($s -eq ' ! No problem detected' ) {
39+ Write-Host " No problem detected." - ForegroundColor DarkYellow
40+ $skipRest = $true
41+ }
42+ else {
43+ if ($errorLine.Length -gt 0 ) {
44+ Write-Error - Message $errorLine
45+ $errorLine = ' '
46+ }
47+ Write-Error - Message $s
4548 }
46- Write-Error - Message $s
49+ }
50+ elseif ($s -match ' ^(Error)|(Fehler)' ) {
51+ $isError = $true
52+ $errorLine = $s
53+ }
54+ elseif ($s -match " ^(`e \[39m)?(`e \[33m)?WARNING" ) {
55+ $s | Write-Warning
56+ }
57+ else {
58+ $s | Write-Verbose
4759 }
4860 }
49- elseif ($s -match ' ^(Error)|(Fehler)' ) {
50- $isError = $true
51- $errorLine = $s
52- }
53- elseif ($s -match " ^(`e \[39m)?(`e \[33m)?WARNING" ) {
54- $s | Write-Warning
55- }
56- else {
57- $s | Write-Verbose
61+ if (-not $skipRest -and -not $isError ) {
62+ Write-Host " done." - ForegroundColor Green
5863 }
5964 }
60- if (-not $skipRest -and -not $isError ) {
61- Write-Host " done." - ForegroundColor Green
62- }
6365}
64-
65- Set-Location - LiteralPath $wd
66+ finally {
67+ Set-Location - LiteralPath $wd
68+ }
0 commit comments