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 'email@example.com' | select ForwardingAddress but it returns the following
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?