none
Enable Mailbox for a AD user RRS feed

  • Question

  • Hi All,

    I am trying to enable an AD user in Exchange. There is a condition where if the Name consists special character we need to create Primary SMTP without special characters and secondary SMTP with special characters. While running the below script it only one primary and two secondary smtp all with special characters.

    Please note that UPN i am inputting did not have any special characters. Kindly assist.

    $Username = "UserName"
    $Password = "Password"
    $ServerName = "Servername"
     
    $securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
    $credential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $Username,$securePassword
    $PSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri connectionURI -Authentication Kerberos -Credential $credential
     
    Import-PSSession $PSSession
     
    $Firstname = "Lambda-s"
    $Lastname = "test"
    $SecondarySMTP = @()
    $AltDisplayName = @()
     
     
    $FN = $Firstname.Trim()
    $LN = $Lastname.Trim()
    $domainSFX = "@domain.com"
    $UPN = "lambda.test@domain.com"
    $Alias = "860121"
    $Database = "DB"
     
    $UserName = "$FN.$LN"
     
    if($UserName -match '-' -or $UserName -match "'")
    {
     
        $SecondarySMTP = "$Firstname.$LastName"+"$domainSFX"
        $AltDisplayName = $UPN
        Enable-Mailbox -Identity $UPN -Database $Database -Alias $Alias
        Set-Mailbox -Identity $UPN -EmailAddresses @{add=$SecondarySMTP}
     
     
     
    }
    else {
        Enable-Mailbox -Identity $UPN -Database $Database -Alias $Alias
    }

    Justin

    • Moved by Bill_Stewart Friday, July 27, 2018 6:43 PM Abandoned
    Friday, May 4, 2018 9:05 AM

All replies

  • Try something like this:

    $SecondarySMTP = ("$Firstname.$LastName").Replace("'","") +"$domainSFX"


    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    Saturday, May 5, 2018 3:30 AM
  • Hi Ed,

    Could you please advise if i could create a secondary SMTP(with special characters) as well while enabling the User mailbox in the same command Primary SMTP ( without special characters)?


    Justin

    Saturday, May 5, 2018 4:04 PM
  • Set-Mailbox -Identity "Mailbox Name" -PrimarySMTPAddress primaryaddress@domain.com -EmailAddresses @{add="smtp:secondaryaddress@domain.com"}


    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!


    Saturday, May 5, 2018 4:47 PM
  • Sorry Ed. But i got an error stating that the PrimarySMTPaddress and Emailaddresses command could not be run together.

    I have an On-Prem Exchange 2010 server which i need to do an action on.


    Justin

    Monday, May 7, 2018 5:25 AM
  • Use two commands.

    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    Monday, May 7, 2018 6:28 PM