add: simplified object build call
This commit is contained in:
@@ -9,6 +9,7 @@ function Test-BlockMailForwarding {
|
|||||||
# Dot source the class script if necessary
|
# Dot source the class script if necessary
|
||||||
#. .\source\Classes\CISAuditResult.ps1
|
#. .\source\Classes\CISAuditResult.ps1
|
||||||
# Initialization code, if needed
|
# Initialization code, if needed
|
||||||
|
$recnum = "6.2.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
process {
|
process {
|
||||||
@@ -37,7 +38,7 @@ function Test-BlockMailForwarding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$params = @{
|
$params = @{
|
||||||
Rec = "6.2.1"
|
Rec = $recnum
|
||||||
Result = $forwardingBlocked
|
Result = $forwardingBlocked
|
||||||
Status = if ($forwardingBlocked) { "Pass" } else { "Fail" }
|
Status = if ($forwardingBlocked) { "Pass" } else { "Fail" }
|
||||||
Details = $details
|
Details = $details
|
||||||
@@ -49,7 +50,7 @@ function Test-BlockMailForwarding {
|
|||||||
Write-Error "An error occurred during the test: $_"
|
Write-Error "An error occurred during the test: $_"
|
||||||
|
|
||||||
# Call Initialize-CISAuditResult with error parameters
|
# Call Initialize-CISAuditResult with error parameters
|
||||||
$auditResult = Initialize-CISAuditResult -Rec "6.2.1" -Failure
|
$auditResult = Initialize-CISAuditResult -Rec $recnum -Failure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,10 +25,10 @@ function Test-MailboxAuditingE5 {
|
|||||||
|
|
||||||
process {
|
process {
|
||||||
try {
|
try {
|
||||||
foreach ($user in $allUsers) {
|
foreach ($user in $allUsers) {
|
||||||
if ($processedUsers.ContainsKey($user.UserPrincipalName)) {
|
if ($processedUsers.ContainsKey($user.UserPrincipalName)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$licenseDetails = Get-MgUserLicenseDetail -UserId $user.UserPrincipalName
|
$licenseDetails = Get-MgUserLicenseDetail -UserId $user.UserPrincipalName
|
||||||
@@ -69,28 +69,28 @@ function Test-MailboxAuditingE5 {
|
|||||||
Write-Verbose "User $($user.UserPrincipalName) does not have an Office E5 license."
|
Write-Verbose "User $($user.UserPrincipalName) does not have an Office E5 license."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# Prepare failure reasons and details based on compliance
|
||||||
|
$failureReasons = if ($allFailures.Count -eq 0) { "N/A" } else { "Audit issues detected." }
|
||||||
|
$details = if ($allFailures.Count -eq 0) { "All Office E5 users have correct mailbox audit settings." } else { $allFailures -join " | " }
|
||||||
|
|
||||||
|
# Populate the audit result
|
||||||
|
$params = @{
|
||||||
|
Rec = $recnum
|
||||||
|
Result = $allFailures.Count -eq 0
|
||||||
|
Status = if ($allFailures.Count -eq 0) { "Pass" } else { "Fail" }
|
||||||
|
Details = $details
|
||||||
|
FailureReason = $failureReasons
|
||||||
|
}
|
||||||
|
$auditResult = Initialize-CISAuditResult @params
|
||||||
}
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "An error occurred during the test: $_"
|
||||||
|
|
||||||
# Prepare failure reasons and details based on compliance
|
# Call Initialize-CISAuditResult with error parameters
|
||||||
$failureReasons = if ($allFailures.Count -eq 0) { "N/A" } else { "Audit issues detected." }
|
$auditResult = Initialize-CISAuditResult -Rec $recnum -Failure
|
||||||
$details = if ($allFailures.Count -eq 0) { "All Office E5 users have correct mailbox audit settings." } else { $allFailures -join " | " }
|
|
||||||
|
|
||||||
# Populate the audit result
|
|
||||||
$params = @{
|
|
||||||
Rec = $recnum
|
|
||||||
Result = $allFailures.Count -eq 0
|
|
||||||
Status = if ($allFailures.Count -eq 0) { "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 $recnum -Failure
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
end {
|
end {
|
||||||
|
Reference in New Issue
Block a user