fix: If details are empty
This commit is contained in:
@@ -72,69 +72,6 @@ function Export-M365SecurityAuditTable {
|
|||||||
[switch]$ExportOriginalTests
|
[switch]$ExportOriginalTests
|
||||||
)
|
)
|
||||||
|
|
||||||
function Initialize-CISAuditResult {
|
|
||||||
[CmdletBinding()]
|
|
||||||
[OutputType([CISAuditResult])]
|
|
||||||
param (
|
|
||||||
[Parameter(Mandatory = $true)]
|
|
||||||
[string]$Rec,
|
|
||||||
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = 'Full')]
|
|
||||||
[bool]$Result,
|
|
||||||
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = 'Full')]
|
|
||||||
[string]$Status,
|
|
||||||
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = 'Full')]
|
|
||||||
[string]$Details,
|
|
||||||
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = 'Full')]
|
|
||||||
[string]$FailureReason,
|
|
||||||
|
|
||||||
[Parameter(ParameterSetName = 'Error')]
|
|
||||||
[switch]$Failure
|
|
||||||
)
|
|
||||||
|
|
||||||
# Import the test definitions CSV file
|
|
||||||
$testDefinitions = $script:TestDefinitionsObject
|
|
||||||
|
|
||||||
# Find the row that matches the provided recommendation (Rec)
|
|
||||||
$testDefinition = $testDefinitions | Where-Object { $_.Rec -eq $Rec }
|
|
||||||
|
|
||||||
if (-not $testDefinition) {
|
|
||||||
throw "Test definition for recommendation '$Rec' not found."
|
|
||||||
}
|
|
||||||
|
|
||||||
# Create an instance of CISAuditResult and populate it
|
|
||||||
$auditResult = [CISAuditResult]::new()
|
|
||||||
$auditResult.Rec = $Rec
|
|
||||||
$auditResult.ELevel = $testDefinition.ELevel
|
|
||||||
$auditResult.ProfileLevel = $testDefinition.ProfileLevel
|
|
||||||
$auditResult.IG1 = [bool]::Parse($testDefinition.IG1)
|
|
||||||
$auditResult.IG2 = [bool]::Parse($testDefinition.IG2)
|
|
||||||
$auditResult.IG3 = [bool]::Parse($testDefinition.IG3)
|
|
||||||
$auditResult.RecDescription = $testDefinition.RecDescription
|
|
||||||
$auditResult.CISControl = $testDefinition.CISControl
|
|
||||||
$auditResult.CISDescription = $testDefinition.CISDescription
|
|
||||||
$auditResult.Automated = [bool]::Parse($testDefinition.Automated)
|
|
||||||
$auditResult.Connection = $testDefinition.Connection
|
|
||||||
$auditResult.CISControlVer = 'v8'
|
|
||||||
|
|
||||||
if ($PSCmdlet.ParameterSetName -eq 'Full') {
|
|
||||||
$auditResult.Result = $Result
|
|
||||||
$auditResult.Status = $Status
|
|
||||||
$auditResult.Details = $Details
|
|
||||||
$auditResult.FailureReason = $FailureReason
|
|
||||||
} elseif ($PSCmdlet.ParameterSetName -eq 'Error') {
|
|
||||||
$auditResult.Result = $false
|
|
||||||
$auditResult.Status = 'Fail'
|
|
||||||
$auditResult.Details = "An error occurred while processing the test."
|
|
||||||
$auditResult.FailureReason = "Initialization error: Failed to process the test."
|
|
||||||
}
|
|
||||||
|
|
||||||
return $auditResult
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($PSCmdlet.ParameterSetName -like "ExportAllResultsFromCsv" -or $PSCmdlet.ParameterSetName -eq "OutputObjectFromCsvSingle") {
|
if ($PSCmdlet.ParameterSetName -like "ExportAllResultsFromCsv" -or $PSCmdlet.ParameterSetName -eq "OutputObjectFromCsvSingle") {
|
||||||
$AuditResults = Import-Csv -Path $CsvPath | ForEach-Object {
|
$AuditResults = Import-Csv -Path $CsvPath | ForEach-Object {
|
||||||
$params = @{
|
$params = @{
|
||||||
@@ -204,7 +141,11 @@ function Export-M365SecurityAuditTable {
|
|||||||
$testDef = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $result.TestNumber }
|
$testDef = $script:TestDefinitionsObject | Where-Object { $_.Rec -eq $result.TestNumber }
|
||||||
if ($testDef) {
|
if ($testDef) {
|
||||||
$fileName = "$ExportPath\$($timestamp)_$($result.TestNumber).$($testDef.TestFileName -replace '\.ps1$').csv"
|
$fileName = "$ExportPath\$($timestamp)_$($result.TestNumber).$($testDef.TestFileName -replace '\.ps1$').csv"
|
||||||
$result.Details | Export-Csv -Path $fileName -NoTypeInformation
|
if ($result.Details.Count -eq 0) {
|
||||||
|
Write-Information "No results found for test number $($result.TestNumber)." -InformationAction Continue
|
||||||
|
} else {
|
||||||
|
$result.Details | Export-Csv -Path $fileName -NoTypeInformation
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user