We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Check Entra account last logon

February 06, 2024 Views: 131

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.

Edit Remove
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
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers