We will be adding email aliases to the proxyaddresses attribute in order to track our Google Apps mailbox aliases (no Exchange here). I currently have a script that Support helped us with and it is checking the mail attribute for change and verifying that the address doesn't exist before creating or modifying the user object. I have even added the proxyaddresses attribute into the LDAP filter in the script and it does work to make sure that an address placed into the mail attribute doesn't already exist as an alias. I now need to also check when an alias is placed into the proxyaddresses attribute to make sure it is not already in use. Proxyaddresses is a multi-value attribute, so I did not know if I could just copy this script and change it to where is pulls the new address from proxyaddresses instead of mail or if it would even work. We may add one or many aliases at one time and will need to insure that the addresses are not in use.
Help with this would be greatly appreciated.
if ($Context.IsPropertyModified("mail"))
{
# Get Email address
$mail = $Context.GetModifiedPropertyValue("mail");
# Check whether the email address is empty
if ([System.String]::IsNullOrEmpty($mail))
{
return
}
# Search all users
$searcher = New-Object "Softerra.Adaxes.Adsi.Search.DirectorySearcher" $NULL, $False
$searcher.SearchParameters.PageSize = 500
$searcher.SearchParameters.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.SearchParameters.Filter = "(&(objectCategory=user)(|(mail=$mail)(proxyaddresses=$mail)))"
$searcher.VirtualRoot = $True
$result = $searcher.ExecuteSearch()
$users = $result.FetchAll()
$result.Dispose()
# Check if the Email address is unique
if($users.Count -ne 0)
{
$Context.Cancel("Email address is already in use. Please verify that account is not being duplicated");
}
}