Script Repository

Save last activity date in Exchange Online to custom attribute

June 07, 2021

The script saves last activity date of the target user in Exchange Online to custom attribute date attribute. To execute the script, create a custom command, scheduled task or business rule configured for the User object type.

In the script, the $propertyName variable specifies the LDAP name of the custom date attribute that will store the last activity date.

Edit Remove
$propertyName = "adm-CustomAttributeDate1" # TODO: modify me

# Check recipient type and location
if ($Context.TargetObject.RecipientLocation -ne "ADM_EXCHANGERECIPIENTLOCATION_OFFICE365" -or
    $Context.TargetObject.RecipientType -ne "ADM_EXCHANGERECIPIENTTYPE_MAILBOXENABLED")

# Get last logon date from Exchange Online
$mailboxParams = $Context.TargetObject.GetMailParameters()
$lastLogonDate = $mailboxParams.UsageInfo.LastLogonDate

if ($lastLogonDate -eq [DateTime]::MinValue)

# Update the user
$Context.TargetObject.Put($propertyName, $lastLogonDate)

Comments ( 0 )
No results found.
Leave a comment