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.
PowerShell
$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")
{
return
}
# Get last logon date from Exchange Online
$mailboxParams = $Context.TargetObject.GetMailParameters()
$lastLogonDate = $mailboxParams.UsageInfo.LastLogonDate
if ($lastLogonDate -eq [DateTime]::MinValue)
{
return
}
# Update the user
$Context.TargetObject.Put($propertyName, $lastLogonDate)
$Context.TargetObject.SetInfo()