0 votes

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
by (460 points)

Please log in or register to answer this question.

Related questions

0 votes
1 answer

Maybe there is a better way to accomplish this, so I'm open to suggestion. We are in a hybrid setup between onprem and M365. When we create a new user, they are ... command in the previous step, right? If needed, I can provide the full script. Thanks!

asked Nov 2, 2023 by AndrewMeyer (20 points)
0 votes
1 answer

Hi, something has happened to our shared mailbox creation, on prem and syncing with o365 (we're a hybrid environment) the process works. With no issues. When a new shared ... I'm assuming at the moment it's an Adaxes issue with accessing the o365 information.

asked Jan 27, 2023 by gazoco (490 points)
0 votes
1 answer

I'm learning the Adaxes powershell methods for creating objects. I would like to create a contact that is mail enabled. I attempted to use the example but it failed ... example of how to create a mail enabled contact with PowerShell using the New-AdmObject?

asked Jul 29, 2020 by ComputerHabit (790 points)
0 votes
1 answer

I've got the following script as part of a larger piece where param-members is an AD Object picker list seperated by a ' ; ' currently: New-DistributionGroup -Name ... or convert that to username but I'm struggling to achieve that with multiple Users selected

asked Jan 27, 2020 by richarddewis (260 points)
0 votes
1 answer

I want to remove special characters on the onboarding web form for username and mail before clicking Finish. Using a script like on the rule "Before User Creation" seems to to do the change to late and you can not verify the email adress before created.

asked Dec 27, 2021 by joem (20 points)
3,348 questions
3,049 answers
7,791 comments
545,062 users