diff --git a/source/tests/Test-MailboxAuditingE3.ps1 b/source/tests/Test-MailboxAuditingE3.ps1 index f9583b4..186a2f6 100644 --- a/source/tests/Test-MailboxAuditingE3.ps1 +++ b/source/tests/Test-MailboxAuditingE3.ps1 @@ -2,6 +2,7 @@ function Test-MailboxAuditingE3 { [CmdletBinding()] param ( # Aligned + # Create Table for Details # Parameters can be added if needed ) diff --git a/source/tests/Test-MailboxAuditingE5.ps1 b/source/tests/Test-MailboxAuditingE5.ps1 index a2ee587..aab4538 100644 --- a/source/tests/Test-MailboxAuditingE5.ps1 +++ b/source/tests/Test-MailboxAuditingE5.ps1 @@ -1,12 +1,20 @@ function Test-MailboxAuditingE5 { [CmdletBinding()] - param () + param ( + # Aligned + # Create Table for Details + # Parameters can be added if needed + ) begin { + # Dot source the class script if necessary + #. .\source\Classes\CISAuditResult.ps1 + $e5SkuPartNumbers = @("SPE_E5", "ENTERPRISEPREMIUM", "OFFICEE5") $AdminActions = @("ApplyRecord", "Copy", "Create", "FolderBind", "HardDelete", "MailItemsAccessed", "Move", "MoveToDeletedItems", "SendAs", "SendOnBehalf", "Send", "SoftDelete", "Update", "UpdateCalendarDelegation", "UpdateFolderPermissions", "UpdateInboxRules") $DelegateActions = @("ApplyRecord", "Create", "FolderBind", "HardDelete", "MailItemsAccessed", "Move", "MoveToDeletedItems", "SendAs", "SendOnBehalf", "SoftDelete", "Update", "UpdateFolderPermissions", "UpdateInboxRules") $OwnerActions = @("ApplyRecord", "Create", "HardDelete", "MailboxLogin", "Move", "MailItemsAccessed", "MoveToDeletedItems", "Send", "SoftDelete", "Update", "UpdateCalendarDelegation", "UpdateFolderPermissions", "UpdateInboxRules") + $auditResult = [CISAuditResult]::new() $auditResult.ELevel = "E5" $auditResult.ProfileLevel = "L1" @@ -31,15 +39,11 @@ function Test-MailboxAuditingE5 { } try { - # Define SKU Part Numbers for Office E5 licenses - # Define SKU Part Numbers for Office E5 licenses - $e5SkuPartNumbers = @("SPE_E5", "ENTERPRISEPREMIUM", "OFFICEE5") $licenseDetails = Get-MgUserLicenseDetail -UserId $user.UserPrincipalName $hasOfficeE5 = ($licenseDetails | Where-Object { $_.SkuPartNumber -in $e5SkuPartNumbers }).Count -gt 0 Write-Verbose "Evaluating user $($user.UserPrincipalName) for Office E5 license." if ($hasOfficeE5) { $userUPN = $user.UserPrincipalName - $mailbox = Get-EXOMailbox -Identity $userUPN -PropertySets Audit $missingActions = @() @@ -78,13 +82,15 @@ function Test-MailboxAuditingE5 { } } - if ($allFailures.Count -eq 0) { - Write-Verbose "All evaluated E5 users have correct mailbox audit settings." - } + # 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 $auditResult.Result = $allFailures.Count -eq 0 $auditResult.Status = if ($auditResult.Result) { "Pass" } else { "Fail" } - $auditResult.Details = if ($auditResult.Result) { "All Office E5 users have correct mailbox audit settings." } else { $allFailures -join " | " } - $auditResult.FailureReason = if (-not $auditResult.Result) { "Audit issues detected." } else { "N/A" } + $auditResult.Details = $details + $auditResult.FailureReason = $failureReasons } end { @@ -117,4 +123,4 @@ function Format-MissingActions { } return $formattedResults -join '; ' -} \ No newline at end of file +}