0

The following command works perfectly:

Set-Mailbox $mailbox -EmailAddresses SMTP:[email protected],[email protected],[email protected]

Trying to run the same command with the email addresses in a variable crashes.

$SMTPAddresses = "SMTP:[email protected],[email protected],[email protected]” 
Set-Mailbox $mailbox -EmailAddresses $SMTPAddress

Error:

Set-Mailbox : Cannot convert 'SMTP:[email protected],[email protected],[email protected]' to the type 'Microsoft.Exchange.Data.ProxyAddressCollection' required by parameter 'EmailAddresses'. The address 'SMTP:[email protected],[email protected],[email protected]' is invalid: The address '[email protected],[email protected],[email protected]' is not a valid SMTP address.
At line:1 char:39
+  Set-Mailbox $mailbox -EmailAddresses $SMTPAddresses
+                                       ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-Mailbox], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Exchange.Management.RecipientTasks.SetMailbox

The variable is a string btw.

 $SMTPAddresses.GetType()

IsPublic IsSerial Name                                     BaseType                                                                                                                            
-------- -------- ----                                     --------                                                                                                                            
True     True     String                                   System.Object 

Any ideas what is causing this?

3 Answers 3

1

The error message is rather self-explanatory. [email protected],[email protected],[email protected] is not an e-mail address. Try it like this:

$SMTPAddresses = 'SMTP:[email protected]','SMTP:[email protected]','SMTP:[email protected]'
Set-Mailbox $mailbox -EmailAddresses $SMTPAddresses
Sign up to request clarification or add additional context in comments.

Comments

1

This is an array of two email address strings:

$SMTPAddresses = "SMTP:[email protected]","[email protected],[email protected]

This is one string of two email addresses joined with a comma:

$SMTPAddresses = "SMTP:[email protected],[email protected],[email protected]

Comments

0

A peculiarity on Office 365 powershell using the xxx-UnifiedGroups command

If you're constructing the command like this:

$emails  = @()
$emails += "SMTP:[email protected]"
$emails += "smtp:[email protected]"

# I'm splatting here but you can use whatever approach you prefer
$params  = @{}
$params += @{"EmailAddresses" = $emails}

And you're getting this error, try making sure you include a tenant address like so:

$emails  = @()
$emails += "SMTP:[email protected]"
$emails += "smtp:[email protected]"
$emails += "smtp:[email protected]"

$params  = @{}
$params += @{"EmailAddresses" = $emails}

Note: Originally I got past the error using escaping, but that was a red herring. After getting full end to end working example it turns out you need a "MOERA" address (one that matches your 365 tenant) but the command gives a false error message about not being able to convert to the type 'Microsoft.Exchange.Data.ProxyAddressCollection'.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.