Script repository
The script saves last activity date of the target user in Exchange Online to custom attribute date attribute. To execute the script, create a business rule, custom command or scheduled task configured for the User object type.
In the script, the $propertyName variable specifies the name of the custom date attribute that will store the last activity date.
$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 11
You must be signed in to comment.
Imre
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 , :line 11
Do you have any idea what should I change?
Support
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.
Imre
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
Support
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/.
Imre
Thank you for your help. The update 7 was the solution. The script works as before. Thank you again.
VolC
This does not work in a hybrid environment.
Support
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.
millie
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
Support
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.
Brent Witmer
It is not working for me. I modified it to do Attribute 6 but nothing happens. we are a hybrid environment and the mailbox is a remote-mailbox. Any help would be appreciated.
Support
Hello Brent,
As per our check, the script works just fine. Such a thing can happen in case one of the if blocks hits the return command. You can try adding an output before the command in both places to find out the one. To make the output, use method
$Context.LogMessage: https://adaxes.com/sdk/ExecuteScriptContextClass/#LogMessage_details.