Link to home
Start Free TrialLog in
Avatar of AutomatedIT
AutomatedIT

asked on

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?
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

you could use -expandproperty or in another variable use $new-variable = $forwardindaddress.forwardingaddress
ASKER CERTIFIED SOLUTION
Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
$forwardingaddress = get-mailbox -identity 'me@me.com' | Select-Object -ExpandProperty -Property ForwardingAddress

Open in new window