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

This topic contains 7 replies, has 2 voices, and was last updated by Profile photo of turbo mcp turbo mcp 1 year, 11 months ago.

  • Author
    Posts
  • #24698
    Profile photo of turbo mcp
    turbo mcp
    Participant

    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
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    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
    Profile photo of turbo mcp
    turbo mcp
    Participant

    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
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    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
      Profile photo of turbo mcp
      turbo mcp
      Participant

      awesome
      thanks

    • #24707
      Profile photo of turbo mcp
      turbo mcp
      Participant

      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
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    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
    Profile photo of turbo mcp
    turbo mcp
    Participant

    yeah I was just wondering,
    Thanks

You must be logged in to reply to this topic.