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 if account is inactive in Exchange longer than a period of time

December 06, 2023 Views: 785

The script returns true if the account is inactive in Exchange longer than a period of time. The script can be executed in the If PowerShell script returns true condition of business rules, custom commands and scheduled tasks.

In the script, the $inactivityDurationThreshold variable specifies the inactivity duration in days that should be exceeded for the condition to be met.

Edit Remove
PowerShell
$inactivityDurationThreshold = 45 # Days. TODO: modify me

# Check recipient type and location
$Context.ConditionIsMet = $False
if ($Context.TargetObject.RecipientLocation -ne "ADM_EXCHANGERECIPIENTLOCATION_EXCHANGEONLINE" -or
    $Context.TargetObject.RecipientType -ne "ADM_EXCHANGERECIPIENTTYPE_MAILBOXENABLED")
{
   return
}

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

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

$date = [System.Datetime]::Now.AddDays(- $inactivityDurationThreshold)
$Context.ConditionIsMet = $lastLogonDate -lt $date
Comments 2
avatar
TB Jan 26, 2022
Hello,
The script return this error :
The property 'ConditionIsMet' cannot be found on this object. Verify that the property exists and can be set. Trace de pile: at <ScriptBlock>, <No file>: line 9

Regards,
TB
avatar
Support Jan 26, 2022
Hello,

The error occurs because you are using the script in the Run a program or PowerShell script action. The ConditionIsMet property is only available in script conditions. As it is specified in the script description, it can only be used in the If PowerShell script returns true condition.
Leave a comment
Loading...

Got questions?

Support Questions & Answers