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.
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
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
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.