Query Details
// This query can help you to obtain which accounts in IdentityInfo table have privileged groups or roles, according to values specified in certain Watchlists.
// IdentityInfo table renews itself completely every ~14 days.
//
// Click "Save as function", in Parameters write in the fields:
// "datetime" "query_date" ""
// "timespan" "query_period" "14d"
//
// If you name the function "PrivilegedIdentityInfo", you can check the function with queries like the following:
//
// PrivilegedIdentityInfo
//
// PrivilegedIdentityInfo(now(), 14d)
//
// let Function = (query_date:datetime, query_period:timespan = 14d){
let _PrivilegedGroupRegex = toscalar(
union
(
_GetWatchlist("SID-AuditADObjects")
| where Notes has_any ("[Privileged]", "[Unpopulated]")
| project RegEx = regex_quote(SAMAccountName)
),
(
_GetWatchlist("RegEx-PrivDomainGroups")
| project RegEx
)
| summarize RegEx = make_set(RegEx)
| extend RegEx = strcat(@"^(", strcat_array(RegEx, "|"), @")$")
);
let _PrivilegedRoleRegex = toscalar(
_GetWatchlist("RegEx-PrivAADRoles")
| summarize RegEx = make_list(RegEx)
| extend RegEx = strcat(@"^(", strcat_array(RegEx, "|"), @")$")
);
IdentityInfo
| where TimeGenerated between ((query_date - query_period) .. query_date)
| summarize arg_max(TimeGenerated, *) by AccountObjectId, AccountSID
| mv-expand GroupMember = GroupMembership to typeof(string), AssignedRole = AssignedRoles to typeof(string)
| where GroupMember matches regex _PrivilegedGroupRegex or AssignedRole matches regex _PrivilegedRoleRegex
| project-away GroupMember, AssignedRole
| summarize take_any(*) by AccountObjectId, AccountSID
// };
// Function(now(), 14d)
This query is designed to identify accounts in the IdentityInfo table that have privileged groups or roles. It uses specific patterns defined in watchlists to determine what constitutes a "privileged" group or role. Here's a simple breakdown of what the query does:
Watchlists for Privileged Groups and Roles:
Data Filtering:
IdentityInfo table, which is updated every 14 days.query_period), ending at a specified date (query_date).Data Processing:
arg_max based on TimeGenerated.GroupMembership and AssignedRoles fields to check each group and role individually.Matching Privileged Groups/Roles:
Result Compilation:
GroupMember and AssignedRole fields from the results.take_any to select any record for each account.In essence, this query helps you find accounts with privileged access by checking against predefined patterns of privileged groups and roles, using data from the IdentityInfo table.

Jose Sebastián Canós
Released: February 3, 2025
Tables
Keywords
Operators