• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2021
  • Last Modified:

Exchange 2010 powershell store primary smtpaddress in a variable

I am trying to write a simple script however I am coming across a strange problem. I would like to store the primarysmtpaddress value in a variable. The code I am using is below which i thought would be very simple but it isnt working as i expected.

$user = get-mailbox hutchl
$mainemail = $user.primarysmtpaddress

Open in new window

Running the command get-mailbox hutchl | select-object primarysmtpaddress returns the results as I expect.
However running the script above does not. It returns multiple values when stored in a variable.
stored in variable

All I am trying to do is store the primarysmtpaddress into a variable of my choosing.
Joseph Daly
Joseph Daly
1 Solution
Primarysmtpaddress is a multivalued property.. to get the Primarysmtpaddress as single value you need to convert it to string..
Joseph DalyAuthor Commented:
Looks like adding the .tostring worked.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Managed Security Services Webinar - March 15

Selecting the right managed security services platform to grow your business can be a huge undertaking. Join WatchGuard and Frost & Sullivan in an upcoming webinar as we dive into the key elements of selecting a vendor platform and partnership to fuel a successful MSSP business.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now