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?
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?
you could use -expandproperty or in another variable use $new-variable = $forwardindaddress.forward ingaddress
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$forwardingaddress = get-mailbox -identity 'me@me.com' | Select-Object -ExpandProperty -Property ForwardingAddress