fix: Fixed merging and added date to columns without a status
This commit is contained in:
@@ -26,6 +26,9 @@ function Merge-CISExcelAndCsvData {
|
||||
$AuditResults
|
||||
}
|
||||
|
||||
# Extract recommendation numbers from the CSV
|
||||
$csvRecs = $csvData | Select-Object -ExpandProperty Rec
|
||||
|
||||
# Ensure headers are included in the merged data
|
||||
$headers = @()
|
||||
$firstItem = $import[0]
|
||||
@@ -36,11 +39,13 @@ function Merge-CISExcelAndCsvData {
|
||||
|
||||
$mergedData = @()
|
||||
foreach ($item in $import) {
|
||||
$csvRow = $csvData | Where-Object { $_.Rec -eq $item.'recommendation #' }
|
||||
if ($csvRow) {
|
||||
# Check if the recommendation number exists in the CSV
|
||||
$recNum = $item.'recommendation #'
|
||||
if ($csvRecs -contains $recNum) {
|
||||
$csvRow = $csvData | Where-Object { $_.Rec -eq $recNum }
|
||||
$mergedData += New-MergedObject -ExcelItem $item -CsvRow $csvRow
|
||||
} else {
|
||||
$mergedData += New-MergedObject -ExcelItem $item -CsvRow ([PSCustomObject]@{Connection=$null; Status=$null; Date=$null; Details=$null; FailureReason=$null})
|
||||
$mergedData += $item
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -35,7 +35,8 @@ function Update-CISExcelWorksheet {
|
||||
}
|
||||
|
||||
# Update the worksheet with the provided data
|
||||
Update-WorksheetCell -Worksheet $worksheet -Data $Data -StartingRowIndex $StartingRowIndex
|
||||
$validRows = $Data | Where-Object { $_.'recommendation #' -ne $null }
|
||||
Update-WorksheetCell -Worksheet $worksheet -Data $validRows -StartingRowIndex $StartingRowIndex
|
||||
|
||||
# Save and close the Excel package
|
||||
Close-ExcelPackage $excelPackage
|
||||
|
Reference in New Issue
Block a user