Add: error handling to tests
This commit is contained in:
@@ -12,37 +12,45 @@ function Test-BlockMailForwarding {
|
||||
}
|
||||
|
||||
process {
|
||||
# 6.2.1 (L1) Ensure all forms of mail forwarding are blocked and/or disabled
|
||||
try {
|
||||
# 6.2.1 (L1) Ensure all forms of mail forwarding are blocked and/or disabled
|
||||
|
||||
# Retrieve the transport rules that redirect messages
|
||||
$transportRules = Get-TransportRule | Where-Object { $null -ne $_.RedirectMessageTo }
|
||||
$forwardingBlocked = $transportRules.Count -eq 0
|
||||
# Retrieve the transport rules that redirect messages
|
||||
$transportRules = Get-TransportRule | Where-Object { $null -ne $_.RedirectMessageTo }
|
||||
$forwardingBlocked = $transportRules.Count -eq 0
|
||||
|
||||
# Prepare failure reasons and details based on compliance
|
||||
$failureReasons = if ($transportRules.Count -gt 0) {
|
||||
"Mail forwarding rules found: $($transportRules.Name -join ', ')"
|
||||
}
|
||||
else {
|
||||
"N/A"
|
||||
}
|
||||
# Prepare failure reasons and details based on compliance
|
||||
$failureReasons = if ($transportRules.Count -gt 0) {
|
||||
"Mail forwarding rules found: $($transportRules.Name -join ', ')"
|
||||
}
|
||||
else {
|
||||
"N/A"
|
||||
}
|
||||
|
||||
$details = if ($transportRules.Count -gt 0) {
|
||||
$transportRules | ForEach-Object {
|
||||
"$($_.Name) redirects to $($_.RedirectMessageTo)"
|
||||
} -join " | "
|
||||
}
|
||||
else {
|
||||
"Step 1: No forwarding rules found. Please proceed with Step 2 described in CIS Benchmark."
|
||||
}
|
||||
$details = if ($transportRules.Count -gt 0) {
|
||||
$transportRules | ForEach-Object {
|
||||
"$($_.Name) redirects to $($_.RedirectMessageTo)"
|
||||
} -join " | "
|
||||
}
|
||||
else {
|
||||
"Step 1: No forwarding rules found. Please proceed with Step 2 described in CIS Benchmark."
|
||||
}
|
||||
|
||||
$params = @{
|
||||
Rec = "6.2.1"
|
||||
Result = $forwardingBlocked
|
||||
Status = if ($forwardingBlocked) { "Pass" } else { "Fail" }
|
||||
Details = $details
|
||||
FailureReason = $failureReasons
|
||||
$params = @{
|
||||
Rec = "6.2.1"
|
||||
Result = $forwardingBlocked
|
||||
Status = if ($forwardingBlocked) { "Pass" } else { "Fail" }
|
||||
Details = $details
|
||||
FailureReason = $failureReasons
|
||||
}
|
||||
$auditResult = Initialize-CISAuditResult @params
|
||||
}
|
||||
catch {
|
||||
Write-Error "An error occurred during the test: $_"
|
||||
|
||||
# Call Initialize-CISAuditResult with error parameters
|
||||
$auditResult = Initialize-CISAuditResult -Rec "6.2.1" -Failure
|
||||
}
|
||||
$auditResult = Initialize-CISAuditResult @params
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
Reference in New Issue
Block a user