|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Validates that OCR configuration for sensitive information detection is enabled. |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | + This test verifies whether Optical Character Recognition (OCR) is configured at the |
| 7 | + tenant level and enabled for at least one supported workload location. OCR enables |
| 8 | + Microsoft Purview policies to detect sensitive information contained within images. |
| 9 | +
|
| 10 | +.NOTES |
| 11 | + Test ID: 35023 |
| 12 | + Category: Information Protection |
| 13 | + Pillar: Data |
| 14 | + Required Module: ExchangeOnlineManagement |
| 15 | + Required Connection: Security & Compliance PowerShell |
| 16 | +#> |
| 17 | + |
| 18 | +function Test-Assessment-35023 { |
| 19 | + [ZtTest( |
| 20 | + Category = 'Information Protection', |
| 21 | + ImplementationCost = 'Medium', |
| 22 | + MinimumLicense = ('Microsoft 365 E5'), |
| 23 | + Pillar = 'Data', |
| 24 | + RiskLevel = 'Medium', |
| 25 | + SfiPillar = 'Protect tenants and production systems', |
| 26 | + TenantType = ('Workforce'), |
| 27 | + TestId = 35023, |
| 28 | + Title = 'OCR is enabled for sensitive information detection', |
| 29 | + UserImpact = 'Low' |
| 30 | + )] |
| 31 | + [CmdletBinding()] |
| 32 | + param() |
| 33 | + |
| 34 | + #region Data Collection |
| 35 | + Write-PSFMessage '🟦 Start' -Tag Test -Level VeryVerbose |
| 36 | + |
| 37 | + $activity = 'Checking OCR configuration' |
| 38 | + Write-ZtProgress -Activity $activity -Status 'Running Get-OcrConfiguration' |
| 39 | + |
| 40 | + $ocrConfig = $null |
| 41 | + $errorMsg = $null |
| 42 | + |
| 43 | + # Q1: Get OCR configuration |
| 44 | + try { |
| 45 | + $ocrConfig = Get-OcrConfiguration -ErrorAction Stop | Select-Object -Property Enabled, ExchangeLocation, SharePointLocation, OneDriveLocation, TeamsLocation, EndpointDlpLocation, IsOcrUsageBlocked, OcrUsageBlockageReason |
| 46 | + } |
| 47 | + catch { |
| 48 | + $errorMsg = $_ |
| 49 | + Write-PSFMessage "Failed to retrieve OCR configuration: $_" -Tag Test -Level Error |
| 50 | + } |
| 51 | + # Q2/Q3: Extract detailed properties if configuration exists |
| 52 | + $enabled = $false |
| 53 | + $exchange = $false |
| 54 | + $sharePoint = $false |
| 55 | + $oneDrive = $false |
| 56 | + $teams = $false |
| 57 | + $endpoint = $false |
| 58 | + $isBlocked = $null |
| 59 | + $blockReason = $null |
| 60 | + $billingStatus = $null |
| 61 | + $enabledLocationsCount = 0 |
| 62 | + |
| 63 | + if ($ocrConfig) { |
| 64 | + $blockReason = $ocrConfig.OcrUsageBlockageReason |
| 65 | + $enabled = $ocrConfig.Enabled |
| 66 | + $exchange = $ocrConfig.ExchangeLocation.Count -gt 0 |
| 67 | + $sharePoint = $ocrConfig.SharePointLocation.Count -gt 0 |
| 68 | + $oneDrive = $ocrConfig.OneDriveLocation.Count -gt 0 |
| 69 | + $teams = $ocrConfig.TeamsLocation.Count -gt 0 |
| 70 | + $endpoint = $ocrConfig.EndpointDlpLocation.Count -gt 0 |
| 71 | + $isBlocked = $ocrConfig.IsOcrUsageBlocked |
| 72 | + |
| 73 | + if ($exchange) { $enabledLocationsCount++ } |
| 74 | + if ($sharePoint) { $enabledLocationsCount++ } |
| 75 | + if ($oneDrive) { $enabledLocationsCount++ } |
| 76 | + if ($teams) { $enabledLocationsCount++ } |
| 77 | + if ($endpoint) { $enabledLocationsCount++ } |
| 78 | + |
| 79 | + $billingStatus = if ($isBlocked) { 'Not Configured' } else { 'Configured' } |
| 80 | + } |
| 81 | + #endregion Data Collection |
| 82 | + |
| 83 | + #region Assessment Logic |
| 84 | + $customStatus = $null |
| 85 | + $passed = $false |
| 86 | + |
| 87 | + if ($errorMsg) { |
| 88 | + $passed = $false |
| 89 | + $customStatus = 'Investigate' |
| 90 | + $testResultMarkdown = "⚠️ Unable to determine OCR configuration status due to permissions issues or query failure. Error: $errorMsg`n`n%TestResult%" |
| 91 | + } |
| 92 | + else { |
| 93 | + $hasConfig = $null -ne $ocrConfig |
| 94 | + $anyLocationEnabled = $enabledLocationsCount -gt 0 |
| 95 | + |
| 96 | + if (-not $hasConfig) { |
| 97 | + $passed = $false |
| 98 | + $testResultMarkdown = "❌ OCR is not configured.`n`n%TestResult%" |
| 99 | + } |
| 100 | + elseif (-not $enabled) { |
| 101 | + $passed = $false |
| 102 | + $testResultMarkdown = "❌ OCR is configured but disabled at the tenant level.`n`n%TestResult%" |
| 103 | + } |
| 104 | + elseif (-not $anyLocationEnabled) { |
| 105 | + $passed = $false |
| 106 | + $testResultMarkdown = "❌ OCR is enabled but not configured for any locations.`n`n%TestResult%" |
| 107 | + } |
| 108 | + elseif ($isBlocked) { |
| 109 | + $passed = $false |
| 110 | + $testResultMarkdown = "❌ OCR usage is blocked.`n`n%TestResult%" |
| 111 | + } |
| 112 | + else { |
| 113 | + $passed = $true |
| 114 | + $testResultMarkdown = "✅ OCR configuration is enabled at the tenant level for at least one workload, enabling policies to detect sensitive information within images.`n`n%TestResult%" |
| 115 | + } |
| 116 | + } |
| 117 | + #endregion Assessment Logic |
| 118 | + |
| 119 | + #region Report Generation |
| 120 | + $mdInfo = '' |
| 121 | + |
| 122 | + if (-not $errorMsg) { |
| 123 | + $reportTitle = 'OCR configuration status' |
| 124 | + $portalLink = 'https://purview.microsoft.com/' |
| 125 | + $portalPathSafe = Get-SafeMarkdown -Text 'Microsoft Purview portal > Settings > Optical character recognition (OCR)' |
| 126 | + |
| 127 | + $configurationObjectStatus = if ($null -ne $ocrConfig) { 'Yes' } else { 'No' } |
| 128 | + |
| 129 | + $tableRows = "| Configuration object exists | $configurationObjectStatus |`n" |
| 130 | + $tableRows += "| OCR enabled (Tenant-level) | $enabled |`n" |
| 131 | + $tableRows += "| Exchange location enabled | $exchange |`n" |
| 132 | + $tableRows += "| SharePoint location enabled | $sharePoint |`n" |
| 133 | + $tableRows += "| OneDrive location enabled | $oneDrive |`n" |
| 134 | + $tableRows += "| Teams location enabled | $teams |`n" |
| 135 | + $tableRows += "| Endpoint location enabled | $endpoint |`n" |
| 136 | + $tableRows += "| OCR usage blocked | $(if ($null -eq $isBlocked) { 'N/A' } else { $isBlocked }) |`n" |
| 137 | + $tableRows += "| Blockage reason | $(if ($blockReason) { $blockReason } else { 'None' }) |`n" |
| 138 | + $tableRows += "| Azure billing status | $(if ($billingStatus) { $billingStatus } else { 'N/A' }) |`n" |
| 139 | + |
| 140 | + $ocrConfiguredStatus = if ($ocrConfig) { 'Configured' } else { 'Not Configured' } |
| 141 | + |
| 142 | + $formatTemplate = @' |
| 143 | +
|
| 144 | +### {0} |
| 145 | +
|
| 146 | +| Setting | Value | |
| 147 | +| :------ | :---- | |
| 148 | +{1} |
| 149 | +
|
| 150 | +**Summary:** |
| 151 | +
|
| 152 | +- OCR configuration: {2} |
| 153 | +- Active locations: {3} |
| 154 | +
|
| 155 | +[{4}]({5}) |
| 156 | +
|
| 157 | +'@ |
| 158 | + $mdInfo = $formatTemplate -f $reportTitle, $tableRows, $ocrConfiguredStatus, $enabledLocationsCount, $portalPathSafe, $portalLink |
| 159 | + } |
| 160 | + |
| 161 | + $testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $mdInfo |
| 162 | + #endregion Report Generation |
| 163 | + |
| 164 | + $params = @{ |
| 165 | + TestId = '35023' |
| 166 | + Title = 'OCR is enabled for sensitive information detection' |
| 167 | + Status = $passed |
| 168 | + Result = $testResultMarkdown |
| 169 | + } |
| 170 | + |
| 171 | + if ($customStatus) { |
| 172 | + $params.CustomStatus = $customStatus |
| 173 | + } |
| 174 | + Add-ZtTestResultDetail @params |
| 175 | +} |
0 commit comments