AzureActivity Table PrincipalId + UserPrincipalName from another Table in KQL

Daniel Gareth Davies 0 Reputation points
2024-07-18T16:21:03.0233333+00:00

Good morning all

I am following Microsoft's official documentation for adding an alert rule that fires when a user adds another user or service principal to a privileged role assignment (e.g. Owner, Contributor). I have achieved this by streaming logs to a Log Analytics Workspace and using a Kusto query on our Azure subscription referencing the AzureActivity table.

However, I have a requirement to display the UserPrincipalName or some kind of friendly name of the PrincipalId of the user/service principal that gets added to that privileged role assignment. I can see the principalId of the user that gets added, and I know that principalId matches the objectId of the user - how can I use this information to get the user's friendly name / UserPrincipalName and display it in the alert that fires?Thanks in advance!

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,011 questions
Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,069 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vahid Ghafarpour 20,480 Reputation points
    2024-07-18T17:53:39.3566667+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    I hope this script helps you:

    Get-AzureADUser -ObjectID "username@domain" | Select-Object DisplayName, UserPrincipalName
    

    If you want to retrieve for all user you can use this script:

    $tid = 'xxxxx-xxx-xxx-xxx-xxxx'  # Replace with your tenant ID
    Connect-AzureAD -TenantId $tid
    $allUsers = Get-AzureADUser -All $true
    $userInfo = $allUsers | Select-Object DisplayName, AccountEnabled, UserPrincipalName
    $userInfo | Export-Csv ./AADusers.csv -NoTypeInformation -Append
    

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful **

    0 comments No comments