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

Save last activity date in Exchange Online to custom attribute

February 07, 2024 Views: 1134

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
PowerShell
$propertyName = "adm-CustomAttributeDate1" # TODO: modify me

# Check recipient type and location
if ($Context.TargetObject.RecipientLocation -ne "ADM_EXCHANGERECIPIENTLOCATION_EXCHANGEONLINE" -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()
Comments 9
avatar
Imre Szabo Nov 28, 2023
Hello,
we used this script, without modification, but somehow now it is not working anymore.

Exception calling "GetMailParameters" with "0" argument(s): "The recipient has neither a mailbox nor an e-mail address. Stack trace: at <Scriptblock>, <No file>:line 11

Do you have any idea what should I change?
avatar
Support Nov 28, 2023
Hello Imre,

Please, specify the version of Adaxes you are currently using. For details on how to check it, see https://www.adaxes.com/help/CheckServiceVersion.

Also, make sure that the account you run the script against is associated with a Microsoft 365 tenant in Adaxes. For information on how to check that, see https://www.adaxes.com/help/LookupTenantForUser.
avatar
Imre Dec 07, 2023
Hello,
so our version is 3.14.19312.0
the user for the tenant is good, we already have different queries and everiyhing else working except this script. We used this for a long time, nobody changed it and it broked somehow. I think maybe Microsoft changed something, but I cannot prove this. If you have a modified script or you can test in your environment, please do it for us. Thx
avatar
Support Dec 07, 2023
Hello Imre,

Microsoft has followed through with its plan to deprecate remote PowerShell in Exchange Online, and it is not available in your tenant anymore. The Adaxes version you are using relies on PowerShell remoting to perform operations in Exchange Online, which means you need to update to a version that uses the Exchange Online Management V3 PowerShell module. You have a choice between updating to Adaxes 2021 Update 7 and upgrading to the latest version.

Upgrade Instructions

Adaxes 2021 Update 7
Download
What's New

Adaxes 2023.2 Update 3
Download
What's New

If you decide to upgrade to the latest version, we recommend you to first check whether your current license key can be used with it. For details, see https://www.adaxes.com/help/CheckUpdates/.
avatar
Imre Dec 08, 2023
Thank you for your help. The update 7 was the solution. The script works as before. Thank you again.
avatar
VolC Feb 07, 2024
This does not work in a hybrid environment.
avatar
Support Feb 07, 2024
Hello,

Unfortunately, there was a mistake in the script. We have just corrected it. Please, give the updated script a try. Should you face any errors/warnings, please, send screenshots to support@adaxes.com.
avatar
millie Jun 12, 2024
Hello, I am trying to run this but I'm not sure where to find the custom attribute that gets populated. Do I need to change anything in the script to match my environment? I'm new to Powershell as well so I'm trying to understand these parameters. Any help is appreciated.

We are running Admin Console v2023.2
Adaxes Service v3.16.21906.0
avatar
Support Jun 13, 2024
Hello,

Each environment of the latest version has 15 custom date attributes: adm-CustomAttributeDate1 - adm-CustomAttributeDate15. You can use any of them. There is no need to change anything else in the script.
Leave a comment
Loading...

Got questions?

Support Questions & Answers