fix: error handling and informative output

This commit is contained in:
DrIOS
2024-06-16 09:22:07 -05:00
parent 949a2aaa43
commit 2d4593f207

View File

@@ -137,6 +137,8 @@ function Export-M365SecurityAuditTable {
if ($ExportPath) {
$timestamp = (Get-Date).ToString("yyyy.MM.dd_HH.mm.ss")
$exportedTests = @()
foreach ($result in $results) {
$testDef = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $result.TestNumber }
if ($testDef) {
@@ -146,9 +148,21 @@ function Export-M365SecurityAuditTable {
}
else {
$result.Details | Export-Csv -Path $fileName -NoTypeInformation
$exportedTests += $result.TestNumber
}
}
}
if ($exportedTests.Count -gt 0) {
Write-Information "The following tests were included in the export: $($exportedTests -join ', ')" -InformationAction Continue
}
else {
if ($ExportOriginalTests) {
Write-Information "No specified tests were included in the export other than the full audit results." -InformationAction Continue
}
else {
Write-Information "No specified tests were included in the export." -InformationAction Continue
}
}
if ($ExportOriginalTests) {
$originalFileName = "$ExportPath\$timestamp`_M365FoundationsAudit.csv"
@@ -156,7 +170,12 @@ function Export-M365SecurityAuditTable {
}
}
elseif ($OutputTestNumber) {
return $results[0].Details
if ($results[0].Details) {
return $results[0].Details
}
else {
Write-Information "No results found for test number $($OutputTestNumber)." -InformationAction Continue
}
}
else {
Write-Error "No valid operation specified. Please provide valid parameters."