How to track users created by a service principal in Microsoft 365?
+
In Microsoft 365, a service principal is a security identity used by applications and automated tools to access resources without a user account. When a service principal creates a user, it typically indicates an application or automated process, not an admin. Periodic tracking of this activity helps identify misconfigured applications, ensures compliance, prevents unauthorized privilege escalation, and maintains control over account creation.
- Navigate to the Microsoft Purview compliance portal.
- Go to Audit»Audit log search, then select Added user from the Activities - friendly names dropdown.
- From the audit log results, look for entries where 'User' is listed as a service principal.
While Microsoft Purview offers detailed audit logs for Microsoft 365 user creations, those are not user-friendly for admins. Instead, admins can use the PowerShell script below to easily identify user accounts created by service principals in their tenant.
Connect to the Exchange Online PowerShell module using the below cmdlet.
Run the following script with the appropriate start date & end date to get the Microsoft 365 user accounts created by service principals.
Search-UnifiedAuditLog -StartDate MM/DD/YYYY -EndDate MM/DD/YYYY -Operations "Add user" -ResultSize 5000 | Where-Object { ($_.AuditData | ConvertFrom-Json).Operation -eq "Add user." } | ForEach-Object {
$auditData = ConvertFrom-Json $_.AuditData
[PSCustomObject]@{
CreationDate = $auditData.CreationTime
UserId = $auditData.UserId
User = $auditData.ObjectId
Operation = $auditData.Operation
}
} | Format-Table -AutoSize
- What role does Microsoft Substrate Management play in user creation? Microsoft Substrate Management is a foundational service in Microsoft 365 that facilitates dual-write operations between Exchange Online and Azure Active Directory (AAD). When a mailbox is created directly in Exchange Online, the corresponding user account in AAD may be created by this service principal. While it primarily ensures synchronization and consistency across services, any user accounts created by it will also appear in audit logs, similar to those created by other service principals.