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
$EmailAddress.GetType()to see its type.