<# .SYNOPSIS Lab 08.4 — Microsoft Purview Sensitivity Labels & DLP Policy Validation (Read-Only + Synthetic) .DESCRIPTION Connects to Microsoft Purview Security & Compliance PowerShell (App-Only certificate or interactive) to verify active Sensitivity Labels (Lab-Cok-Gizli) and DLP policy modes (TestWithNotifications vs Enable). Optionally creates a strictly synthetic non-PII test file for manual label/DLP upload testing. Classification : Read-only audit + synthetic test helper (SAFE · SYNTHETIC) Required Roles : Compliance Administrator / Security Reader (App-Only or interactive) .NOTES Author : Caner Cetinkaya (canercetinkaya.com/labs/08-attack-and-validate/) Safety : SAFE · SYNTHETIC (Zero real PII, TCKN, or IBAN values) #> [CmdletBinding()] param( [string]$AppConfigPath = 'D:\Lab\.purview-app.json', [switch]$CreateSyntheticFile, [string]$SyntheticPath = 'C:\Temp\SYNTHETIC-DLP-TEST-01.txt' ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' Import-Module ExchangeOnlineManagement -ErrorAction Stop if (Test-Path $AppConfigPath) { Write-Host "[1/3] Connecting to Purview IPPS via App-Only config ($AppConfigPath)..." -ForegroundColor Cyan $cfg = Get-Content $AppConfigPath -Raw | ConvertFrom-Json Connect-IPPSSession -AppId $cfg.AppId -CertificateThumbprint $cfg.Thumbprint -Organization $cfg.Organization -ShowBanner:$false } else { Write-Host '[1/3] Connecting to Purview IPPS interactively...' -ForegroundColor Cyan Connect-IPPSSession -ShowBanner:$false } try { Write-Host '[2/3] Verifying published Sensitivity Labels...' -ForegroundColor Cyan Get-Label | Select-Object Name, DisplayName, Priority, Disabled | Format-Table -AutoSize Write-Host '[3/3] Verifying DLP Policies and Enforcement Modes (TestWithNotifications != Block)...' -ForegroundColor Cyan Get-DlpCompliancePolicy | Select-Object Name, Mode, Enabled, Workload | Format-Table -AutoSize } finally { Disconnect-ExchangeOnline -Confirm:$false -ErrorAction SilentlyContinue } if ($CreateSyntheticFile) { $parent = Split-Path $SyntheticPath -Parent if ($parent) { New-Item -ItemType Directory -Force -Path $parent | Out-Null } @( 'SYNTHETIC LAB VALIDATION DOCUMENT - NO REAL PII' 'DocumentID : SYNTHETIC-DLP-TEST-01' 'ProjectTag : PRJ-LAB-2026-ALPHA' 'Purpose : Microsoft Purview Sensitivity Label & DLP Audit Verification' ) | Set-Content -Path $SyntheticPath -Encoding UTF8 Write-Host "Synthetic non-PII test file created at: $SyntheticPath (Delete after validation)." -ForegroundColor Green }