I have written an offboarding Workflow for immediate terminations. The sequence of events is as follows:
Here is my problem. The HR user only sees that the job is complete; they do not see if there were errors during execution. I have logging configured throughout the script and I want to send an email to the user who triggered the Workflow in step 1 above, but I cannot find a way to get that user's UPN when they triggered the Workflow. How can I get the UPN of the person who is activating a EntraID Identity Governance Lifecycle Workflow?
Initially, I created one sample Entra ID Identity Governance Lifecycle Workflow as below:
To know who activated the workflow, you can check Audit logs of Lifecycle Workflows by filtering based on specific activities and categories:
To get these details via Graph API, you can run below GET request in Graph Explorer filtering with specific Activity Name based on your need:
GET https://graph.microsoft.com/v1.0/auditLogs/directoryAudits?$filter=category eq 'WorkflowManagement' and loggedByService eq 'Lifecycle Workflows' and activityDisplayName eq 'Set workflow for on-demand execution' and targetResources/any(tr:tr/displayName eq 'Workflow Name')
Response:
Alternatively, you can make use of below PowerShell script to get the UPN of the person who is activating the Lifecycle workflow:
# Connect to Microsoft Graph with necessary permissions
Connect-MgGraph -Scopes "AuditLog.Read.All"
# Define the filter query to get audit logs for Lifecycle Workflows with the specific activity name and target resource display name
$targetResourceDisplayName = "Immediate termination" # Replace with your workflow name
$filterQuery = "category eq 'WorkflowManagement' and loggedByService eq 'Lifecycle Workflows' and activityDisplayName eq 'Set workflow for on-demand execution' and targetResources/any(tr:tr/displayName eq '$targetResourceDisplayName')"
# Retrieve the audit logs using the filter query
$auditLogs = Get-MgAuditLogDirectoryAudit -Filter $filterQuery
# Extract and display UPN of the user who initiated each workflow and the target resource display name
foreach ($log in $auditLogs) {
$initiatorUPN = $log.InitiatedBy.User.UserPrincipalName
$targetResourceDisplayName = $log.TargetResources[0].DisplayName
Write-Output "Lifecycle Workflow initiated by: $initiatorUPN on target resource: $targetResourceDisplayName"
}
Response:
Reference:
Auditing Lifecycle Workflows - Microsoft Entra ID Governance