MDI Service Accounts Without Service Principals And MS As
Query
IdentityInfo
| where Timestamp > ago(30d)
| where Type == @"ServiceAccount"
| extend ["Service On-Prem Sid"] = OnPremObjectId
| extend ["Service Principal Name"] = iff(IdentityEnvironment == "OnPremises",replace_string(strcat(AccountName, "@",AccountDomain),"$",""), AccountUpn )
| where parse_json(UserAccountControl)[0] != 'WorkstationTrustAccount' //Exclude gMSA/dMSA
| where not (ChangeSource == @"System-UserPersistence" and isempty(CloudSid)) //Exclude Service Principals
| summarize arg_max(Timestamp,*) by AccountObjectId,CloudSid,['Service On-Prem Sid']Explanation
This KQL query is designed to filter and summarize information about service accounts from the IdentityInfo table. Here's a breakdown in simpler terms:
-
Time Filter: It selects records from the last 30 days (
Timestamp > ago(30d)). -
Type Filter: It focuses specifically on entries where the
Typeis "ServiceAccount". -
Data Extension:
- It creates a new column called "Service On-Prem Sid" using the existing
OnPremObjectIdfield. - It creates another column called "Service Principal Name". This name is constructed differently depending on the environment:
- If the environment is "OnPremises", it combines
AccountNameandAccountDomain, removing any trailing "$". - Otherwise, it uses
AccountUpn.
- If the environment is "OnPremises", it combines
- It creates a new column called "Service On-Prem Sid" using the existing
-
Account Type Exclusion: It excludes accounts identified as 'WorkstationTrustAccount' by checking the
UserAccountControlfield. -
Service Principal Exclusion: It excludes entries where the
ChangeSourceis "System-UserPersistence" andCloudSidis empty, which typically represents service principals. -
Summarization: Finally, it summarizes the data to keep only the most recent entry (
arg_max(Timestamp,*)) for each unique combination ofAccountObjectId,CloudSid, and "Service On-Prem Sid".
In essence, this query filters and processes service account data to provide a concise summary of the most recent relevant entries, excluding certain types of accounts and service principals.
Details

Jay Kerai
Released: June 23, 2026
Tables
Keywords
Operators