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

Welcome Forums General PowerShell Q&A Email address policy customization, all letters or numbers up to @ sign

This topic contains 7 replies, has 2 voices, and was last updated by

 
Participant
3 years, 7 months ago.

  • Author
    Posts
  • #24698

    Participant
    Points: 1
    Rank: Member

    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 david23@testing.com.

    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 firstname.lastname@testing.com 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

  • #24700

    Moderator
    Points: 24
    Team Member
    Rank: Member

    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.

    https://technet.microsoft.com/en-us/library/hh847811.aspx

  • #24701

    Participant
    Points: 1
    Rank: Member

    Thanks
    im on it
    im thinking of something like this:

    $string=Get-Mailbox |Select-Object PrimarySmtpAddress
    $split=$string.primarysmtpaddress.Split("{@}")
    $before=$split.GetValue(0)
    $before
    set-mailbox -ErrorAction:Stop -Identity $user.identity -EmailAddresses @{Add=($before + "@" + "new.mail.onmicrosoft.com")}
    $newemail=Get-Mailbox |Select-Object -expand -property emailaddresses

  • #24702

    Moderator
    Points: 24
    Team Member
    Rank: Member

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

    $NewDomain = 'new.mail.onmicrosoft.com'
    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
        }
    }
    
    • #24706

      Participant
      Points: 1
      Rank: Member

      awesome
      thanks

    • #24707

      Participant
      Points: 1
      Rank: Member

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

  • #24708

    Moderator
    Points: 24
    Team Member
    Rank: Member

    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.

  • #24709

    Participant
    Points: 1
    Rank: Member

    yeah I was just wondering,
    Thanks

The topic ‘Email address policy customization, all letters or numbers up to @ sign’ is closed to new replies.