From 399288b10a1152cb4ea007fdf83317678a539a5f Mon Sep 17 00:00:00 2001 From: DrIOS <58635327+DrIOSX@users.noreply.github.com> Date: Thu, 30 May 2024 16:41:38 -0500 Subject: [PATCH] add: add score to console host --- CHANGELOG.md | 1 + source/Public/Invoke-M365SecurityAudit.ps1 | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04e4966..6f2c164 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on and uses the types of changes according to [Keep a Change - Test definitions filter function. - Logging function for future use. +- Test grade written to console. ### Changed diff --git a/source/Public/Invoke-M365SecurityAudit.ps1 b/source/Public/Invoke-M365SecurityAudit.ps1 index ad7af38..e8a29ee 100644 --- a/source/Public/Invoke-M365SecurityAudit.ps1 +++ b/source/Public/Invoke-M365SecurityAudit.ps1 @@ -228,6 +228,18 @@ function Invoke-M365SecurityAudit { # Clean up sessions Disconnect-M365Suite -RequiredConnections $requiredConnections } + # Calculate the total number of tests + $totalTests = $allAuditResults.Count + + # Calculate the number of passed tests + $passedTests = $allAuditResults.ToArray() | Where-Object { $_.Result -eq $true } | Measure-Object | Select-Object -ExpandProperty Count + + # Calculate the pass percentage + $passPercentage = if ($totalTests -eq 0) { 0 } else { [math]::Round(($passedTests / $totalTests) * 100, 2) } + + # Display the pass percentage to the user + Write-Host "Audit completed. $passedTests out of $totalTests tests passed." -ForegroundColor Cyan + Write-Host "Your passing percentage is $passPercentage%." # Return all collected audit results return $allAuditResults.ToArray() # Check if the Disconnect switch is present