Doms
Doms

Reputation: 113

Powershell Variable format

I am trying to call a variable and use it as an -forwardingsmtpaddress in a command. Why can I type the email address in the command, it works. The variable is a string value. Is the header messing it up?

The variable and output is:

  $EmailAddress

  Emailaddress
 ----------------
 [email protected] 


 C:\Windows\system32> Set-Mailbox -identity $loginid -ForwardingSmtpAddress "$emailaddress"

 emailaddress                                                                                                                                 

 ------------                                                                                                                                 

 [email protected]                                                                                                                  

 ' isn't a valid SMTP address. Property Name: ForwardingSmtpAddress
 At C:\Users\xxx\AppData\Local\Temp\tmp_eaj0q1mh.s1i\tmp_eaj0q1mh.s1i.psm1:51509 char:9
 +         $steppablePipeline.End()
 +         ~~~~~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo          : NotSpecified: (0:Int32) [Set-Mailbox], DataValidationException
 + FullyQualifiedErrorId : BDB22E0A,Microsoft.Exchange.Management.RecipientTasks.SetMailbox
 + PSComputerName        : mail01

Upvotes: 0

Views: 250

Answers (1)

mjolinor
mjolinor

Reputation: 68341

It looks like $emailaddress is an object with a property of emailaddress.

Try:

Set-Mailbox -identity $loginid -ForwardingSmtpAddress $emailaddress.emailaddress

Edit: if the variable really is a string then yes, that header is definitely going to mess it up.

Upvotes: 1

Related Questions