New Page
<#
Praktijkleren Examenopdracht – PowerShell
Onderwerp: Logbestand analyseren
Auteur: <jouw naam>
Datum: <datum>
Dit script analyseert een logbestand en telt
het aantal foutmeldingen.
#>
function Lees-Logbestand {
param (
[string]$Bestandsnaam
)
if (Test-Path $Bestandsnaam) {
return Get-Content $Bestandsnaam
}
else {
Write-Host "Bestand niet gevonden." -ForegroundColor Red
return $null
}
}
function Tel-Fouten {
param (
[string[]]$Regels
)
$foutTeller = 0 # variabele
foreach ($regel in $Regels) { # lus
if ($regel.Contains("ERROR")) { # beslissing
$foutTeller++
}
}
return $foutTeller
}
# Hoofdprogramma
$bestandsnaam = "logbestand.txt" # variabele
$regels = Lees-Logbestand -Bestandsnaam $bestandsnaam
if ($null -eq $regels) { return }
$fouten = Tel-Fouten -Regels $regels
Write-Host "`nAnalyse resultaat:"
Write-Host "Aantal regels in bestand:" $regels.Count
Write-Host "Aantal foutmeldingen:" $fouten
No comments to display
No comments to display