Email address policy customization, all letters or numbers up to @ sign

Hi there

I am trying to create a script that will check whatever is the primary email for a user

lets say david23@test.corp copy whats before the @ sign and assign a new policy

for example

the long story:

I have a lot of users that aren’t using the default email policy so they have custom email address that I have no clue what they are(thousands of users like that) so if I modify the default email policy that’s based on firstname.lastname@test.corp and just add it wont apply for them, so I have to find away to add the relevant email for these.

more of powershell thing then exchange.

Thanks a lot for any advice

Please search for 'PowerShell regular expressions email address" using your favourite search engine. Alternatively use the -split operator or Split method on a string variable containing the email address.

im on it
im thinking of something like this:

$string=Get-Mailbox |Select-Object PrimarySmtpAddress
set-mailbox -ErrorAction:Stop -Identity $user.identity -EmailAddresses @{Add=($before + “@” + “”)}
$newemail=Get-Mailbox |Select-Object -expand -property emailaddresses

I do not have access to Exchange but you should be able to do something like below:

$NewDomain = ''
foreach ($Mailbox in Get-Mailbox) {

    if ($Mailbox.PrimarySmtpAddress -notlike "@$NewDomain") {
        $LocalPart = $Mailbox.PrimarySmtpAddress.Split('@')[0]

        $Mailbox | Set-Mailbox -EmailAddresses @{
            Add = ($LocalPart + "@$NewDomain")

        ($Mailbox | Get-Mailbox).EmailAddresses


I have a small stupid question(for my learning)
how would I know that “add” is an option on the emailaddresses property?
Thanks again

The help or online documentation of the cmdlet should tell you how to use the parameters. Unfortunately the Exchange cmdlet documentation is lacking in that area. You will need to use your favorite search engine to find out what is going on, unfortunately.

yeah I was just wondering,