fix: error handling and informative output
This commit is contained in:
@@ -137,6 +137,8 @@ function Export-M365SecurityAuditTable {
|
|||||||
|
|
||||||
if ($ExportPath) {
|
if ($ExportPath) {
|
||||||
$timestamp = (Get-Date).ToString("yyyy.MM.dd_HH.mm.ss")
|
$timestamp = (Get-Date).ToString("yyyy.MM.dd_HH.mm.ss")
|
||||||
|
$exportedTests = @()
|
||||||
|
|
||||||
foreach ($result in $results) {
|
foreach ($result in $results) {
|
||||||
$testDef = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $result.TestNumber }
|
$testDef = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $result.TestNumber }
|
||||||
if ($testDef) {
|
if ($testDef) {
|
||||||
@@ -146,9 +148,21 @@ function Export-M365SecurityAuditTable {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$result.Details | Export-Csv -Path $fileName -NoTypeInformation
|
$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) {
|
if ($ExportOriginalTests) {
|
||||||
$originalFileName = "$ExportPath\$timestamp`_M365FoundationsAudit.csv"
|
$originalFileName = "$ExportPath\$timestamp`_M365FoundationsAudit.csv"
|
||||||
@@ -156,7 +170,12 @@ function Export-M365SecurityAuditTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($OutputTestNumber) {
|
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 {
|
else {
|
||||||
Write-Error "No valid operation specified. Please provide valid parameters."
|
Write-Error "No valid operation specified. Please provide valid parameters."
|
||||||
|
|||||||
Reference in New Issue
Block a user