Powershell Output to Variable Help

Trying to pull 2 outputs from Powershell into variables that I can use in the subject and body of an email sent with the send-mailmessage command.

The first variable I need the ForwardingAddress in the Get-Mailbox command.  I can get this output captured to a variable but it includes the formatting in addition to the name of the distribution group set as the forwarding address.  I need just the distribution group name in the variable.

I have been using $forwardingaddress = get-mailbox -identity 'me@me.com' | select ForwardingAddress but it returns the following
ForwardingAddress
--------------------------
Sales Disty

I need a way to pull just "Sales Disty" into the variable $forwardingaddress.

I then need to take this variable and use it to pull the members of the distribution group and save them as a variable.  This variable needs to be a full list of all members.

Both variables need to be able to be used in the Subject (Disty Name) and the Body (Members of Disty) with the send-mailmessage command.

Can someone help me with the coding on this one?
LVL 1
AutomatedITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
you could use -expandproperty or in another variable use $new-variable = $forwardindaddress.forwardingaddress
0
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
It's simple just run this:

$forwardingaddress = get-mailbox -identity 'me@me.com' | select -ExpandProperty ForwardingAddress

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David Johnson, CD, MVPOwnerCommented:
$forwardingaddress = get-mailbox -identity 'me@me.com' | Select-Object -ExpandProperty -Property ForwardingAddress

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.