|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Purview Audit Logging Enabled |
| 4 | +#> |
| 5 | + |
| 6 | +function Test-Assessment-35037 { |
| 7 | + [ZtTest( |
| 8 | + Category = 'Data Security Posture Management', |
| 9 | + ImplementationCost = 'Low', |
| 10 | + MinimumLicense = ('Microsoft 365 E3'), |
| 11 | + Pillar = 'Data', |
| 12 | + RiskLevel = 'High', |
| 13 | + SfiPillar = 'Protect tenants and production systems', |
| 14 | + TenantType = ('Workforce','External'), |
| 15 | + TestId = 35037, |
| 16 | + Title = 'Purview audit logging enabled', |
| 17 | + UserImpact = 'Low' |
| 18 | + )] |
| 19 | + [CmdletBinding()] |
| 20 | + param() |
| 21 | + |
| 22 | + #region Data Collection |
| 23 | + Write-PSFMessage '🟦 Start' -Tag Test -Level VeryVerbose |
| 24 | + $activity = 'Checking Purview audit logging configuration' |
| 25 | + |
| 26 | + # Query Q1: Get unified audit logging configuration |
| 27 | + Write-ZtProgress -Activity $activity -Status 'Getting audit log configuration' |
| 28 | + |
| 29 | + $errorMsg = $null |
| 30 | + $auditConfig = $null |
| 31 | + |
| 32 | + try { |
| 33 | + $auditConfig = Get-AdminAuditLogConfig -ErrorAction Stop |
| 34 | + Write-PSFMessage "Retrieved audit log configuration" -Level Verbose |
| 35 | + } |
| 36 | + catch { |
| 37 | + $errorMsg = $_ |
| 38 | + Write-PSFMessage "Error querying audit log configuration: $_" -Level Error |
| 39 | + } |
| 40 | + #endregion Data Collection |
| 41 | + |
| 42 | + #region Assessment Logic |
| 43 | + if ($errorMsg -or -not $auditConfig) { |
| 44 | + Write-PSFMessage 'Not connected to Exchange Online.' -Level Warning |
| 45 | + Add-ZtTestResultDetail -SkippedBecause NotConnectedExchange |
| 46 | + return |
| 47 | + } |
| 48 | + |
| 49 | + $passed = $false |
| 50 | + |
| 51 | + if ($auditConfig.UnifiedAuditLogIngestionEnabled -eq $true) { |
| 52 | + $passed = $true |
| 53 | + $testResultMarkdown = "✅ Purview Audit Logging is ENABLED and all activities across Microsoft 365 services are being captured and logged for investigation and compliance purposes.`n`n%TestResult%" |
| 54 | + } |
| 55 | + else { |
| 56 | + $passed = $false |
| 57 | + $testResultMarkdown = "❌ Purview Audit Logging is DISABLED, creating a critical visibility gap where unauthorized access, policy violations, and security incidents cannot be detected or investigated.`n`n%TestResult%" |
| 58 | + } |
| 59 | + |
| 60 | + #endregion Assessment Logic |
| 61 | + |
| 62 | + #region Report Generation |
| 63 | + $mdInfo = '' |
| 64 | + |
| 65 | + # Show audit configuration only if we have data |
| 66 | + if ($null -ne $auditConfig) { |
| 67 | + $mdInfo += "`n`n### [Audit logging status](https://purview.microsoft.com/audit)`n" |
| 68 | + $mdInfo += "| Configuration property | Value |`n" |
| 69 | + $mdInfo += "| :--- | :--- |`n" |
| 70 | + |
| 71 | + $auditStatus = $auditConfig.UnifiedAuditLogIngestionEnabled |
| 72 | + $ageLimit = if ($auditConfig.AdminAuditLogAgeLimit) { $auditConfig.AdminAuditLogAgeLimit } else { 'Not configured' } |
| 73 | + $organizationId = if ($auditConfig.OrganizationId) { Get-SafeMarkdown -Text $auditConfig.OrganizationId } else { 'N/A' } |
| 74 | + |
| 75 | + $mdInfo += "| Unified audit log ingestion enabled | $auditStatus |`n" |
| 76 | + $mdInfo += "| Audit log age limit | $ageLimit |`n" |
| 77 | + $mdInfo += "| Organization ID | $organizationId |" |
| 78 | + } |
| 79 | + |
| 80 | + $testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $mdInfo |
| 81 | + #endregion Report Generation |
| 82 | + |
| 83 | + $params = @{ |
| 84 | + TestId = '35037' |
| 85 | + Title = 'Purview audit logging enabled' |
| 86 | + Status = $passed |
| 87 | + Result = $testResultMarkdown |
| 88 | + } |
| 89 | + |
| 90 | + Add-ZtTestResultDetail @params |
| 91 | +} |
0 commit comments