Create and deploy Microsoft Purview DLP policies across Exchange Online, SharePoint, OneDrive, Microsoft Teams, and Endpoints. Configure sensitive information types, policy rules, user notifications, endpoint DLP controls, and incident management workflows.
Microsoft Purview Data Loss Prevention (DLP) protects sensitive information across your Microsoft 365 environment and endpoint devices. In this lab you will create DLP policies that detect and protect credit card numbers, Social Security numbers, health records, and custom sensitive data types. You will deploy policies to Exchange Online (email), SharePoint Online & OneDrive (documents), Microsoft Teams (chat and channels), and Windows endpoints (file copy, print, clipboard). By the end of this lab, you will have a comprehensive DLP framework that prevents accidental and intentional data exposure across all major channels.
A healthcare organisation with 8,000 employees processes patient health information (PHI) across email, SharePoint, and endpoint devices. They must comply with HIPAA, state privacy laws, and their own data handling policies. Recent audits revealed that employees routinely share patient records via email without encryption, save PHI to personal USB drives, and paste sensitive data into Teams chats. The CISO needs a DLP solution that prevents data loss across all channels while minimising disruption to legitimate business workflows.
Data breaches cost organisations an average of $4.88 million per incident (IBM 2024). DLP is the primary control that prevents sensitive data from leaving your organisation through email, cloud storage, or endpoint devices. Without DLP, employees can accidentally (or intentionally) share customer PII, financial data, or intellectual property via unsecured channels. A well-deployed DLP framework reduces breach risk, demonstrates regulatory compliance (GDPR, HIPAA, PCI-DSS), and creates a culture of data awareness through real-time policy tips that educate users at the point of action.
A DLP policy consists of rules that detect sensitive information and take protective actions. Understanding the components before creating policies ensures effective protection without over-blocking.
Start by protecting the most common data loss channel: email. Create a DLP policy that detects sensitive information in emails and attachments.
DLP-Exchange-FinancialDatacompliance-team@contoso.com# Connect to Security & Compliance PowerShell
# WHY: Required session for all DLP, sensitivity label, and compliance cmdlets
Connect-IPPSSession -UserPrincipalName admin@contoso.com
# Create the DLP policy targeting Exchange email
# WHAT: Creates a DLP policy container scoped to all Exchange mailboxes
# -Mode TestWithNotifications: SIMULATION mode - shows policy tips to users
# but does NOT block emails. Always start here before enforcing.
# OUTPUT: Policy appears in Purview portal under DLP > Policies
New-DlpCompliancePolicy -Name "DLP-Exchange-FinancialData" `
-ExchangeLocation All `
-Mode TestWithNotifications `
-Comment "Protect financial data in email. simulation mode"
# Create the low-volume rule (1-9 credit card numbers)
# WHAT: Detects emails containing 1 to 9 credit card numbers at high confidence
# WHY: Low-volume matches suggest accidental inclusion - educate the user
# rather than blocking, and log for compliance review
# -NotifyUser: Shows a policy tip to the site admin and last modifier
# -GenerateIncidentReport: Sends a detailed report to the admin for audit
# -IncidentReportContent "All": Includes full message content in the report
New-DlpComplianceRule -Name "DLP-Exchange-Financial-LowVolume" `
-Policy "DLP-Exchange-FinancialData" `
-ContentContainsSensitiveInformation @{
Name = "Credit Card Number";
minCount = 1;
maxCount = 9;
confidencelevel = "High"
} `
-NotifyUser "SiteAdmin","LastModifier" `
-NotifyUserType "NotifyUser" `
-GenerateIncidentReport "SiteAdmin" `
-IncidentReportContent "All"
# Create the high-volume rule (10+ credit card numbers)
# WHAT: Detects bulk credit card data (10+ instances) - likely a data dump
# WHY: High volume = high risk of breach. Block immediately with no override.
# -BlockAccess $true: Prevents the email from being sent entirely
# -GenerateAlert: Creates a high-severity alert for immediate SOC investigation
# -AggregationType "None": Each match generates its own alert (no batching)
# CONCERN: 10+ credit cards in one email strongly suggests exfiltration or error
New-DlpComplianceRule -Name "DLP-Exchange-Financial-HighVolume" `
-Policy "DLP-Exchange-FinancialData" `
-ContentContainsSensitiveInformation @{
Name = "Credit Card Number";
minCount = 10;
confidencelevel = "High"
} `
-BlockAccess $true `
-GenerateAlert "SiteAdmin" `
-AlertProperties @{AggregationType = "None"}TestWithNotifications mode to show policy tips without blocking. This educates users about what would be blocked when you switch to enforcement, dramatically reducing support tickets on go-live day.Built-in SITs cover common data types, but most organisations have custom sensitive data (employee IDs, project codes, internal account numbers). Create custom SITs to detect your organisation’s specific data patterns.
Contoso Employee IDEMP-[0-9]{6}employee, staff, personnel# Create a custom sensitive information type (SIT) via PowerShell
# WHAT: Defines a custom SIT using XML rule pack format to detect organisation-specific
# data patterns that built-in SITs don't cover (e.g., employee IDs)
# WHY: Every organisation has unique data formats. Custom SITs let DLP policies
# protect your proprietary identifiers alongside standard PII.
$rulePackXml = @"
<RulePackage xmlns="http://schemas.microsoft.com/office/2011/mce">
<RulePack id="$(New-Guid)">
<Version major="1" minor="0" build="0" revision="0"/>
<Publisher id="$(New-Guid)"/>
<Details defaultLangCode="en-us">
<LocalizedDetails langcode="en-us">
<PublisherName>Contoso Ltd</PublisherName>
<Name>Contoso Custom SITs</Name>
<Description>Custom sensitive information types for Contoso</Description>
</LocalizedDetails>
</Details>
</RulePack>
<Rules>
<Entity id="$(New-Guid)" patternsProximity="300" recommendedConfidence="85">
<Pattern confidenceLevel="85">
<IdMatch idRef="EmployeeId"/>
<Match idRef="EmployeeKeywords"/>
</Pattern>
</Entity>
<Regex id="EmployeeId">EMP-[0-9]{6}</Regex>
<Keyword id="EmployeeKeywords">
<Group matchStyle="word">
<Term>employee</Term>
<Term>staff</Term>
<Term>personnel</Term>
</Group>
</Keyword>
</Rules>
</RulePackage>
"@
# Save the XML rule definition to a file
$rulePackXml | Out-File -FilePath "ContosoSIT.xml" -Encoding utf8
# Upload the custom SIT rule package to the compliance centre
# OUTPUT: The "Contoso Employee ID" SIT becomes available in DLP policy conditions
# PATTERN: Matches EMP- followed by exactly 6 digits (e.g., EMP-004521)
# SUPPORTING KEYWORDS: "employee", "staff", "personnel" within 300 chars boost confidence
New-DlpSensitiveInformationTypeRulePackage -FileData ([System.IO.File]::ReadAllBytes("ContosoSIT.xml"))Protect documents stored in SharePoint Online and OneDrive for Business. DLP scans document content and blocks sharing when sensitive data is detected.
DLP-SharePoint-PII# Create DLP policy for SharePoint and OneDrive document protection
# WHAT: Scans documents stored in SharePoint Online and OneDrive for sensitive data
# WHY: Documents containing PII must be protected from external sharing to comply
# with GDPR, CCPA, and HIPAA regulations
# -Mode TestWithNotifications: Simulation mode - shows policy tips without blocking
New-DlpCompliancePolicy -Name "DLP-SharePoint-PII" `
-SharePointLocation All `
-OneDriveLocation All `
-Mode TestWithNotifications
# Add rule to detect SSN and block external sharing
# WHAT: Triggers when 5+ SSNs are found in a single document (high confidence)
# WHY: 5+ SSNs suggests a data export or report - must not be shared externally
# -BlockAccess $true: Prevents the document from being shared
# -BlockAccessScope "SpecificExternalUsers": Blocks external users only; internal
# users retain access. This prevents data leaks while allowing internal workflows.
# -GenerateIncidentReport: Sends alert details to the site administrator
New-DlpComplianceRule -Name "DLP-SP-PII-Block" `
-Policy "DLP-SharePoint-PII" `
-ContentContainsSensitiveInformation @{
Name = "U.S. Social Security Number (SSN)";
minCount = 5;
confidencelevel = "High"
} `
-BlockAccess $true `
-BlockAccessScope "SpecificExternalUsers" `
-GenerateIncidentReport "SiteAdmin"Teams DLP scans chat messages and channel messages for sensitive information. When a policy match is found, the message is blocked or a policy tip is shown to the sender.
DLP-Teams-HealthDataEndpoint DLP extends data protection to Windows devices, controlling USB file copy, printing, clipboard operations, and uploads to cloud services. This requires devices onboarded to Microsoft Defender for Endpoint.
C:\Program Files\)DLP-Endpoint-SensitiveData# Create Endpoint DLP policy for Windows device protection
# WHAT: Creates a DLP policy scoped to Windows endpoints onboarded to Defender for Endpoint
# WHY: Protects data on the device itself - prevents USB copy, printing, clipboard,
# and cloud upload of sensitive files. Covers the "last mile" of data protection.
# -EndpointDlpLocation All: Applies to all onboarded Windows devices
# -Mode TestWithNotifications: Audit mode first - log activity without blocking
New-DlpCompliancePolicy -Name "DLP-Endpoint-SensitiveData" `
-EndpointDlpLocation All `
-Mode TestWithNotifications
# Add rule with endpoint-specific actions for sensitive data
# WHAT: Detects credit cards or SSNs on endpoint devices and applies granular controls
# -ContentContainsSensitiveInformation: Matches EITHER credit cards OR SSNs (minCount=1)
# -EndpointDlpRestrictions: Endpoint-specific actions per data channel:
# CopyToRemovableMedia=Block: Prevents copying to USB drives (top exfiltration vector)
# Print=Warn: Shows a warning before printing (allows override with justification)
# CopyToClipboard=Audit: Logs clipboard activity but doesn't block (minimises disruption)
# UploadToCloudService=Block: Prevents upload to non-corporate cloud services (Dropbox, etc.)
# AccessByUnallowedApps=Block: Prevents unapproved apps from opening sensitive files
New-DlpComplianceRule -Name "DLP-Endpoint-BlockUSB" `
-Policy "DLP-Endpoint-SensitiveData" `
-ContentContainsSensitiveInformation @{
Name = "Credit Card Number";
minCount = 1;
confidencelevel = "High"
},@{
Name = "U.S. Social Security Number (SSN)";
minCount = 1;
confidencelevel = "High"
} `
-EndpointDlpRestrictions @(
@{Setting="CopyToRemovableMedia";Value="Block"},
@{Setting="Print";Value="Warn"},
@{Setting="CopyToClipboard";Value="Audit"},
@{Setting="UploadToCloudService";Value="Block"},
@{Setting="AccessByUnallowedApps";Value="Block"}
)Policy tips are the user-facing component of DLP. They educate users in real-time when they are about to share sensitive data, reducing incidents by up to 80% according to Microsoft data.
Configure alerts that notify the compliance team when DLP policies trigger. Set up incident reports for investigation and audit purposes.
dlp-alerts@contoso.com# List all DLP policies and their current status
# WHAT: Shows every DLP policy in the tenant with its enforcement mode and scope
# OUTPUT: Name, Mode (Enable/TestWithNotifications/TestWithoutNotifications),
# IsEnabled, and which locations (Exchange, SharePoint) are protected
# CONCERN: Any policy in "Enable" mode is actively blocking - verify this is intentional
Get-DlpCompliancePolicy | Format-Table Name, Mode, IsEnabled, ExchangeLocation, SharePointLocation
# View DLP policy rule details for the Exchange financial data policy
# WHAT: Shows the SIT conditions and actions for each rule in the policy
# OUTPUT: ContentContainsSensitiveInformation (which SITs trigger the rule),
# BlockAccess (whether the rule blocks or just warns)
Get-DlpComplianceRule -Policy "DLP-Exchange-FinancialData" |
Format-List Name, ContentContainsSensitiveInformation, BlockAccess
# Search the unified audit log for DLP match events
# WHAT: Retrieves DLP policy match events from the last 7 days
# WHY: Review which policies are triggering, for which users, and how often
# -RecordType DLP: Filters to DLP-specific audit events only
# OUTPUT: Date, user who triggered the policy, and the operation (DLPRuleMatch)
# USE: Monitor daily to catch false positives early in the simulation phase
Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-7) `
-EndDate (Get-Date) `
-RecordType DLP `
-ResultSize 50 |
Select-Object CreationDate, UserIds, Operations |
Format-Table -AutoSizeBefore enforcing DLP policies, run them in simulation mode for at least 1–2 weeks. Review the results to tune sensitivity thresholds and reduce false positives.
4111-1111-1111-1111 (standard test number)# Switch policy from simulation to full enforcement
# WHAT: Changes the DLP policy from test mode to active blocking mode
# WHY: After validating simulation results (1-2 weeks, <5% false positive rate),
# switch to enforcement so the policy actually blocks sensitive data sharing
# CAUTION: This immediately starts blocking emails matching the policy rules
Set-DlpCompliancePolicy -Identity "DLP-Exchange-FinancialData" -Mode Enable
# Verify the mode change was applied
# OUTPUT: Mode should now show "Enable" and IsEnabled should be "True"
# EXPECT: If Mode still shows "TestWithNotifications", the change may need a few minutes
Get-DlpCompliancePolicy -Identity "DLP-Exchange-FinancialData" |
Select-Object Name, Mode, IsEnabledAdaptive Protection connects DLP with Insider Risk Management to automatically adjust DLP policy strictness based on a user’s risk level. High-risk users get stricter controls; low-risk users get lighter enforcement.
Use Activity Explorer and DLP reports to monitor policy effectiveness, identify trends, and report to leadership.
# Export DLP policy match data from the audit log for the past 30 days
# WHAT: Retrieves all DLP events for monthly compliance reporting
# WHY: Monthly DLP reports demonstrate regulatory compliance and help tune policies
# -ResultSize 5000: Maximum per call; use paging for larger tenants
$dlpEvents = Search-UnifiedAuditLog `
-StartDate (Get-Date).AddDays(-30) `
-EndDate (Get-Date) `
-RecordType DLP `
-ResultSize 5000
# Summarise matches by policy name
# WHAT: Groups all DLP events by which policy triggered them
# OUTPUT: Policy name and match count - shows which policies are most active
# CONCERN: A single policy with very high counts may be too broad (false positives)
# CONCERN: A policy with zero counts may have misconfigured conditions
$dlpEvents |
ForEach-Object { ($_.AuditData | ConvertFrom-Json).PolicyDetails.PolicyName } |
Group-Object |
Sort-Object Count -Descending |
Format-Table Name, Count
# Export raw event data to CSV for detailed analysis in Excel or Power BI
$dlpEvents |
Select-Object CreationDate, UserIds, Operations, AuditData |
Export-Csv -Path "DLP-Report-30Days.csv" -NoTypeInformationReview your DLP deployment and plan ongoing operations.
| Resource | Description |
|---|---|
| Learn about data loss prevention | Overview of DLP capabilities across Microsoft 365 |
| Create and deploy a DLP policy | Step-by-step guide to creating your first DLP policy |
| Learn about Endpoint DLP | Endpoint data loss prevention for Windows devices |
| Sensitive information types | Built-in and custom SIT reference |
| DLP policy tips reference | Configure user-facing notifications and policy tips |
| DLP alerts dashboard | Monitor and investigate DLP policy matches |
| Adaptive protection | Integrate DLP with Insider Risk Management for risk-based enforcement |
| DLP PowerShell reference | Automate DLP policy management with PowerShell |