I am using adm-CustomAttributeText2 to capture external email address. And then using the same to create mail enabled exchange account. But I would like to restrict the external email address to around 70 odd approved domains. So nobody can just enable any account for mail enabled feature for other unknown public email domains. How do I compare this attribute with a csv list of email domains and if domain is in the list only then enable & send an email on success. Else reject with a friendly error message on the web page.
$exchangeServer = "ex01"
# Connect to Exchange Server
$session = New-PSSession -Configurationname Microsoft.Exchange –ConnectionUri http://$exchangeServer/powershell
Import-PSSession $session -DisableNameChecking -AllowClobber
# Enable Mail User
Enable-MailUser "%distinguishedName%" -ExternalEmailAddress %adm-CustomAttributeText2%
Set-MailUser "%distinguishedName%" -EmailAddressPolicyEnabled $false
$PrimaryEmail = (Get-MailUser "%distinguishedName%"| select -ExpandProperty emailaddresses | where{$_ -like "*@hello.com"}) -replace "Smtp:"
Set-MailUser "%distinguishedName%" -PrimarySMTPAddress $PrimaryEmail
Set-MailUser "%distinguishedName%" -EmailAddressPolicyEnabled $true
# Close connection to Exchange Server
Remove-PSSession $session