Hello,
Was wondering if there is a script for a business rule or a property pattern that can be used for this request. I am wondering how can I do a check anytime a user is modified that checks if the email address (Proxy Address and Mail) values are not already present in the AD. If they are then id like it to error and let the person know that the SMTP address is already taken.
Essentially when editing a user account and assigning it a new email address id like a check to be done to confirm uniqueness and then allow to proceed if its unique. I have something like this but doesnt work and errors no matter what.
Import-Module Adaxes
function IsMailUnique($isOnPremiseObject, $emailAddress)
{
if ($isOnPremiseObject)
{
$filter = {mail -eq $emailAddress -or proxyAddresses -contains "SMTP:$emailAddress"}
}
else
{
$filter = {mail -eq $emailAddress -or proxyAddresses -contains "SMTP:$emailAddress"}
}
$domain = $Context.GetObjectDomain("%distinguishedName%")
$user = Get-AdmUser -Filter $filter -Server $domain -AdaxesService localhost
return $null -eq $user
}
$isOnPremiseObject = $Context.TargetObject.DirectoryType -eq 1
$emailAddress = $Context.GetModifiedPropertyValue("mail")
$proxyAddresses = $Context.GetModifiedPropertyValue("proxyAddresses")
if (-not (IsMailUnique $isOnPremiseObject $emailAddress))
{
$Context.LogMessage("The email address '$emailAddress' is already in use.", "Information")
return $true
}
else
{
$Context.LogMessage("The email address '$emailAddress' is available.", "Information")
return $false
}