0

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
3
  • 1
    Your variable is probably a PSObject rather than a string. Type $EmailAddress.GetType() to see its type. Commented Jul 24, 2014 at 17:49
  • @Bill_Stewart pegged it - if it were a string it wouldn't have the Emailaddress header when you get the value. Commented Jul 24, 2014 at 17:50
  • I piped it to get-member and see typename.system.string. But gettype shows name string and basetype as system.object. I can't call it when I type $emailaddres.emailaddress it is not listed as an option to choose and comes up blank. Commented Jul 24, 2014 at 21:34

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I had piped it to out-string when messing with it. Your solution worked except for the -forwardingsmtpaddress vs -forwardingaddress. I wanted the forwardingaddress so i can see it in the GUI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.