The script checks whether the last logon date of the related Entra user account equals the current date. To execute the script, use the If PowerShell script returns true condition in a business rule, custom command or scheduled task configured for the User object type.
In the script, the $daysToAdd variable specifies the number of days to deduct from the current date for comparison with the Last Logon Timestamp of the Entra ID account.
PowerShell
$daysToAdd = -14 # TODO: modify me
$Context.ConditionIsMet = $False
# Bind to Entra account
try
{
$guid = $Context.TargetObject.Get("adm-AzureId")
}
catch
{
return
}
$entraAccount = $Context.BindToObject("Adaxes://<GUID=$guid>")
# Get Entra last logon date
try
{
# Output Last Logon date/time
$lastLogonTimeStamp = $entraAccount.Get("lastLogonTimestamp")
$lastLogonTime = [DateTime]::FromFileTime([Int64]::Parse($lastLogonTimestamp))
}
catch
{
return
}
# Compare dates
$compareDate = ([System.DateTime]::UtcNow).AddDays($daysToAdd)
$Context.ConditionIsMet = $lastLogonTime.Date -eq $compareDate.Date