introlux
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:
Any ideas?
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
}
Any ideas?
ASKER
Yes
ASKER
Also a good alias to also add if possible we would like firstname initial. Surname @domain.com
But not ciritical
But not ciritical
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Error on the last script:
Cannot process argument transformation on parameter 'EmailAddresses'. Cannot convert value "System.Collections.Hashta ble" to type "Microsoft.Exchange.Data.P roxyAddres sCollectio n". Error: "MultiValuedProperty collections cannot contain null values.
Parameter name: item"
+ CategoryInfo : InvalidData: (:) [Set-Mailbox], ParameterBindin. ..mationException
+ FullyQualifiedErrorId : ParameterArgumentTransform ationError ,Set-Mailb ox
Cannot process argument transformation on parameter 'EmailAddresses'. Cannot convert value "System.Collections.Hashta
Parameter name: item"
+ CategoryInfo : InvalidData: (:) [Set-Mailbox], ParameterBindin. ..mationException
+ FullyQualifiedErrorId : ParameterArgumentTransform
ASKER
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.Config uration.Ta sks.Mailbo xIdParamet er". Error: "Cannot convert hashtable to an object of the following type:
Microsoft.Exchange.Configu ration.Tas ks.Mailbox IdParamete r. Hashtable-to-Object
conversion is not supported in restricted language mode or a Data section."
+ CategoryInfo : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationEx ception
+ FullyQualifiedErrorId : ParameterArgumentTransform ationError ,Set-Mailb ox
Cannot process argument transformation on parameter 'Identity'. Cannot convert
value "firstname.surname" to type "Microsoft.Exchange.Config
Microsoft.Exchange.Configu
conversion is not supported in restricted language mode or a Data section."
+ CategoryInfo : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationEx
+ FullyQualifiedErrorId : ParameterArgumentTransform
ASKER
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}
}
ASKER
Thanks!
so you basically need to add an additional smtp address for all mailbox with alias@contoso.com address?
Regards
Mahesh