diff --git a/reports/Validation Report/build-reports.ps1 b/reports/Validation Report/build-reports.ps1 index 29876a9..9b1dfb3 100644 --- a/reports/Validation Report/build-reports.ps1 +++ b/reports/Validation Report/build-reports.ps1 @@ -17,49 +17,52 @@ $depts = ( ).organisationUnitGroups[0].organisationUnits.code | Where-Object -FilterScript { $_ -match $SiteCodeFilter } | Sort-Object $wd = Get-Location -Set-Location -LiteralPath $PSScriptRoot +try { + Set-Location -LiteralPath $PSScriptRoot -foreach ($site in $depts) { - Write-Host "Generating validation report for $site..." - $outFile = "$([datetime]::Now.ToString('yyyy-MM-dd_HHmmss'))_NeoIPC-Surveillance-Validation-Report_$($site).$($Language).pdf" - $skipRest = $false - $errorLine = '' - $isError = $false - quarto render --profile $Language -P "language:$Language" -P "token:../../../token.txt" -P "departmentFilter:$($site)" -o $outFile 2>&1 | ForEach-Object -Process { - if ($skipRest) { - return - } - $s = "$_" - if ($s -eq 'System.Management.Automation.RemoteException') { - $s = '' - } - if ($isError) { - if ($s -eq '! No problem detected') { - Write-Host "No problem detected." -ForegroundColor DarkYellow - $skipRest = $true + foreach ($site in $depts) { + Write-Host "Generating validation report for $site..." + $outFile = "$([datetime]::Now.ToString('yyyy-MM-dd_HHmmss'))_NeoIPC-Surveillance-Validation-Report_$($site).$($Language).pdf" + $skipRest = $false + $errorLine = '' + $isError = $false + quarto render --profile $Language -P "language:$Language" -P "token:../../../token.txt" -P "departmentFilter:$($site)" -o $outFile 2>&1 | ForEach-Object -Process { + if ($skipRest) { + return } - else { - if ($errorLine.Length -gt 0) { - Write-Error -Message $errorLine - $errorLine = '' + $s = "$_" + if ($s -eq 'System.Management.Automation.RemoteException') { + $s = '' + } + if ($isError) { + if ($s -eq '! No problem detected') { + Write-Host "No problem detected." -ForegroundColor DarkYellow + $skipRest = $true + } + else { + if ($errorLine.Length -gt 0) { + Write-Error -Message $errorLine + $errorLine = '' + } + Write-Error -Message $s } - Write-Error -Message $s + } + elseif ($s -match '^(Error)|(Fehler)') { + $isError = $true + $errorLine = $s + } + elseif ($s -match "^(`e\[39m)?(`e\[33m)?WARNING") { + $s | Write-Warning + } + else { + $s | Write-Verbose } } - elseif ($s -match '^(Error)|(Fehler)') { - $isError = $true - $errorLine = $s - } - elseif ($s -match "^(`e\[39m)?(`e\[33m)?WARNING") { - $s | Write-Warning - } - else { - $s | Write-Verbose + if (-not $skipRest -and -not $isError) { + Write-Host "done." -ForegroundColor Green } } - if (-not $skipRest -and -not $isError) { - Write-Host "done." -ForegroundColor Green - } } - -Set-Location -LiteralPath $wd +finally { + Set-Location -LiteralPath $wd +}