From 5871294210ee1f740aa63d390539a35ee2c840ec Mon Sep 17 00:00:00 2001 From: DrIOS <58635327+DrIOSX@users.noreply.github.com> Date: Sat, 8 Jun 2024 13:01:39 -0500 Subject: [PATCH] add: progress bar and surpressed verbose progress. --- source/Private/Invoke-TestFunction.ps1 | 2 +- source/Public/Invoke-M365SecurityAudit.ps1 | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/source/Private/Invoke-TestFunction.ps1 b/source/Private/Invoke-TestFunction.ps1 index 2dea2d0..d9a5997 100644 --- a/source/Private/Invoke-TestFunction.ps1 +++ b/source/Private/Invoke-TestFunction.ps1 @@ -17,7 +17,7 @@ function Invoke-TestFunction { } # Use splatting to pass parameters - Write-Host "Running $functionName..." + Write-Verbose "Running $functionName..." try { $result = & $functionName @paramList # Assuming each function returns an array of CISAuditResult or a single CISAuditResult diff --git a/source/Public/Invoke-M365SecurityAudit.ps1 b/source/Public/Invoke-M365SecurityAudit.ps1 index c3b49ba..93c7eb9 100644 --- a/source/Public/Invoke-M365SecurityAudit.ps1 +++ b/source/Public/Invoke-M365SecurityAudit.ps1 @@ -166,8 +166,14 @@ function Invoke-M365SecurityAudit { $testsFolderPath = Join-Path -Path $PSScriptRoot -ChildPath "tests" $testFiles = Get-ChildItem -Path $testsFolderPath -Filter "Test-*.ps1" | Where-Object { $testsToLoad -contains $_.BaseName } + + $totalTests = $testFiles.Count + $currentTestIndex = 0 + # Import the test functions $testFiles | ForEach-Object { + $currentTestIndex++ + Write-Progress -Activity "Loading Test Scripts" -Status "Loading $($currentTestIndex) of $($totalTests): $($_.Name)" -PercentComplete (($currentTestIndex / $totalTests) * 100) Try { # Dot source the test function . $_.FullName @@ -179,8 +185,11 @@ function Invoke-M365SecurityAudit { } } + $currentTestIndex = 0 # Execute each test function from the prepared list foreach ($testFunction in $testFiles) { + $currentTestIndex++ + Write-Progress -Activity "Executing Tests" -Status "Executing $($currentTestIndex) of $($totalTests): $($testFunction.Name)" -PercentComplete (($currentTestIndex / $totalTests) * 100) $functionName = $testFunction.BaseName if ($PSCmdlet.ShouldProcess($functionName, "Execute test")) { $auditResult = Invoke-TestFunction -FunctionFile $testFunction -DomainName $DomainName @@ -201,3 +210,4 @@ function Invoke-M365SecurityAudit { return $allAuditResults.ToArray() | Sort-Object -Property Rec } } +