Skip to content

/commands/purview/dlp-policy-cmdlets

Create a Purview DLP policy with PowerShell: New-DlpCompliancePolicy and New-DlpComplianceRule

The commands on this page have not been executed by our verification runner yet.updated
tool
Microsoft Purview (Security & Compliance PowerShell)
versions
Security & Compliance PowerShell, ExchangeOnlineManagement 3.x
os
windows, linux, macos

A Microsoft Purview data loss prevention (DLP) policy is created in two steps in Security & Compliance PowerShell: the policy (where it applies and in which mode) and one or more rules (what to detect and what to do). Connect with Connect-IPPSSession first.

powershell
New-DlpCompliancePolicy -Name "US Financial" -ExchangeLocation All -SharePointLocation All -OneDriveLocation All -Mode TestWithNotifications

New-DlpComplianceRule -Name "Block SSN" -Policy "US Financial" `
  -ContentContainsSensitiveInformation @{Name="U.S. Social Security Number (SSN)"} `
  -BlockAccess $true -NotifyUser Owner -GenerateIncidentReport SiteAdmin

The policy starts in simulation mode with notifications; switch it on when the results look right:

powershell
Set-DlpCompliancePolicy -Identity "US Financial" -Mode Enable

Policy mode

-Mode valueEffect
EnableActions and notifications are applied (the default)
TestWithNotificationsSimulation: no actions, notifications are sent
TestWithoutNotificationsSimulation: no actions, no notifications
DisableThe policy is off

Locations

New-DlpCompliancePolicy accepts -ExchangeLocation, -SharePointLocation, -OneDriveLocation, -TeamsLocation, -EndpointDlpLocation (devices), -OnPremisesScannerDlpLocation, -PowerBIDlpLocation and -ThirdPartyAppDlpLocation. Most take All or a list of mailboxes, sites or accounts.

Common rule actions

ParameterValues
-ContentContainsSensitiveInformationHashtable(s) with the sensitive information type Name, optionally minCount, minConfidence
-BlockAccess$true blocks access to the matching item (owner, author and site owner keep access)
-NotifyUserAn email address, LastModifier, Owner or SiteAdmin
-GenerateIncidentReportAn email address or SiteAdmin

Use the exact name of the sensitive information type. List them with:

powershell
Get-DlpSensitiveInformationType | Sort-Object Name | Format-Table Name,Publisher

Check what exists

powershell
Get-DlpCompliancePolicy | Format-Table Name,Mode,Enabled
Get-DlpComplianceRule -Policy "US Financial" | Format-List Name,BlockAccess,ContentContainsSensitiveInformation

Sources