From 46d71900ce8330821b9f4837544742dd073f78ee Mon Sep 17 00:00:00 2001 From: DrIOS <58635327+DrIOSX@users.noreply.github.com> Date: Sun, 16 Jun 2024 12:48:15 -0500 Subject: [PATCH] docs: finalize error handling standard --- source/Private/Get-ExceededLengthResultDetail.ps1 | 12 +++++++++--- source/Public/Export-M365SecurityAuditTable.ps1 | 4 ++-- source/Public/Invoke-M365SecurityAudit.ps1 | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/source/Private/Get-ExceededLengthResultDetail.ps1 b/source/Private/Get-ExceededLengthResultDetail.ps1 index bd2b956..ea2bee5 100644 --- a/source/Private/Get-ExceededLengthResultDetail.ps1 +++ b/source/Private/Get-ExceededLengthResultDetail.ps1 @@ -15,7 +15,10 @@ function Get-ExceededLengthResultDetail { [Parameter(Mandatory = $true, ParameterSetName = 'ReturnExceedingTests')] [switch]$ReturnExceedingTestsOnly, - [int]$DetailsLengthLimit = 30000 + [int]$DetailsLengthLimit = 30000, + + [Parameter(Mandatory = $true, ParameterSetName = 'UpdateArray')] + [int]$PreviewLineCount = 50 ) $exceedingTests = @() @@ -28,11 +31,14 @@ function Get-ExceededLengthResultDetail { if ($ReturnExceedingTestsOnly) { $exceedingTests += $auditResult.Rec } else { + $previewLines = ($auditResult.Details -split '\r?\n' | Select-Object -First $PreviewLineCount) -join "`n" + $message = "The test result is too large to be exported to CSV. Use the audit result and the export function for full output.`n`nPreview:`n$previewLines" + if ($ExportedTests -contains $auditResult.Rec) { Write-Information "The test result for $($auditResult.Rec) is too large for CSV and was included in the export. Check the exported files." - $auditResult.Details = "The test result is too large to be exported to CSV. Use the audit result and the export function for full output." + $auditResult.Details = $message } else { - $auditResult.Details = "The test result is too large to be exported to CSV. Use the audit result and the export function for full output." + $auditResult.Details = $message } } } diff --git a/source/Public/Export-M365SecurityAuditTable.ps1 b/source/Public/Export-M365SecurityAuditTable.ps1 index 4790139..e2beb1a 100644 --- a/source/Public/Export-M365SecurityAuditTable.ps1 +++ b/source/Public/Export-M365SecurityAuditTable.ps1 @@ -153,7 +153,7 @@ function Export-M365SecurityAuditTable { } } if ($exportedTests.Count -gt 0) { - Write-Information "The following tests were included in the export: $($exportedTests -join ', ')" -InformationAction Continue + Write-Information "The following tests were exported: $($exportedTests -join ', ')" -InformationAction Continue } else { if ($ExportOriginalTests) { @@ -169,7 +169,7 @@ function Export-M365SecurityAuditTable { $TestNumbersToCheck = "1.1.1", "1.3.1", "6.1.2", "6.1.3", "7.3.4" # Check for large details and update the AuditResults array - $updatedAuditResults = Get-ExceededLengthResultDetail -AuditResults $AuditResults -TestNumbersToCheck $TestNumbersToCheck -ExportedTests $exportedTests -DetailsLengthLimit 30000 + $updatedAuditResults = Get-ExceededLengthResultDetail -AuditResults $AuditResults -TestNumbersToCheck $TestNumbersToCheck -ExportedTests $exportedTests -DetailsLengthLimit 30000 -PreviewLineCount 25 $originalFileName = "$ExportPath\$timestamp`_M365FoundationsAudit.csv" $updatedAuditResults | Export-Csv -Path $originalFileName -NoTypeInformation } diff --git a/source/Public/Invoke-M365SecurityAudit.ps1 b/source/Public/Invoke-M365SecurityAudit.ps1 index 54671fb..cfc5aed 100644 --- a/source/Public/Invoke-M365SecurityAudit.ps1 +++ b/source/Public/Invoke-M365SecurityAudit.ps1 @@ -293,7 +293,7 @@ function Invoke-M365SecurityAudit { $exceedingTests = Get-ExceededLengthResultDetail -AuditResults $allAuditResults -TestNumbersToCheck $TestNumbersToCheck -ReturnExceedingTestsOnly -DetailsLengthLimit 30000 if ($exceedingTests.Count -gt 0) { Write-Information "The following tests exceeded the details length limit: $($exceedingTests -join ', ')" -InformationAction Continue - Write-Host "(Assuming the results were instantiated. Ex: `$object = invoke-M365SecurityAudit) Use the following command and adjust as neccesary to view the full details of the test results:" -ForegroundColor Gray + Write-Host "(Assuming the results were instantiated. Ex: `$object = invoke-M365SecurityAudit) Use the following command and adjust as neccesary to view the full details of the test results:" -ForegroundColor DarkCyan Write-Host "Export-M365SecurityAuditTable -ExportAllTests -AuditResults `$object -ExportPath `"C:\temp`" -ExportOriginalTests" -ForegroundColor Green } return $allAuditResults.ToArray() | Sort-Object -Property Rec