Author Posts

April 25, 2015 at 3:56 am

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

April 25, 2015 at 4:47 am

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.

April 25, 2015 at 5:09 am

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

April 25, 2015 at 5:50 am

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

April 25, 2015 at 6:17 am


April 25, 2015 at 6:30 am

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

April 25, 2015 at 6:43 am

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.

April 25, 2015 at 7:11 am

yeah I was just wondering,