Link to home
Start Free TrialLog in
Avatar of introlux
introluxFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Office 365 - Add Alias - contoso.com

Hi Experts,

Trying to add alias addresses to all mailbox accounts so that they can have @contoso.com as an additional mailbox.

I have come up with this script but it does not seem to work:

$Users = Get-Mailbox

Foreach ($User in $Users){

   $ProxyAddresses = (Get-Mailbox $user.alias).emailaddresses
   Foreach ($address in $ProxyAddresses) {
        If (($Address.PrefixString -eq "smtp") -and ($address.AddressString.split("@")[1] `
        -eq "contoso.com")) {
              $ProxyAddresses += $Address
        }
   }
   Set-Mailbox $user.alias -EmailAddresses $ProxyAddresses 
}

Open in new window


Any ideas?
Avatar of Mahesh Sharma
Mahesh Sharma
Flag of United States of America image

Hi

so you basically need to add an additional smtp address for all mailbox with alias@contoso.com address?

Regards
Mahesh
Avatar of introlux

ASKER

Yes
Also a good alias to also add if possible we would like firstname initial. Surname @domain.com

But not ciritical
ASKER CERTIFIED SOLUTION
Avatar of Mahesh Sharma
Mahesh Sharma
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Error on the last script:

Cannot process argument transformation on parameter 'EmailAddresses'. Cannot convert value "System.Collections.Hashtable" to type "Microsoft.Exchange.Data.ProxyAddressCollection". Error: "MultiValuedProperty collections cannot contain null values.
Parameter name: item"
    + CategoryInfo          : InvalidData: (:) [Set-Mailbox], ParameterBindin.   ..mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox
Sorry the last error was my fault. here is the correct error:

Cannot process argument transformation on parameter 'Identity'. Cannot convert
value "firstname.surname" to type "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter". Error: "Cannot convert hashtable to an object of the following type:
 Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter. Hashtable-to-Object
 conversion is not supported in restricted language mode or a Data section."
    + CategoryInfo          : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox
Here is the script I am trying to run:

 $Users = Get-Mailbox -resultsize unlimited

 Foreach ($User in $Users){
 
 $a = Get-user $user.alias
 $FI = ($a.firstname).substring(0,1)
 $LName = $a.LastName
 $Email = $FI + $LName + "@contoso.com" 
 Set-Mailbox $a -EmailAddresses @{Add= $Email}
 
 }

Open in new window

Thanks!