Reputation: 25
i think it is a really simple question for powershell experts, but i found no results on google because i do not know the right keywords. Here is the Question (Powershell):
Example:
Command-A | Command-B | Export-CSV result.csv
how to get all properties/columns from Command-A and B in the csv file? On my case only the columns from Command-B were exported.
What i'm actually try is:
Get-Mailbox | Get-ADPermission | Select-Object -Property (some columns from mailbox and adperms) Export-CSV result.csv
Thanks for help, Best.
Upvotes: 2
Views: 1653
Reputation: 5227
Tee-Object
with saving to variables should help with that. The example below contains alias
property from Get-Mailbox
. You can add more with the same method.
NOTE: Linebreaks added for visibility
Get-Mailbox -identity sometestmbx |
Tee-Object -Variable mbx|
Get-AdPermission |
Select-Object identity, user, deny, isinherited, # From Get-AdPermission
@{name="MbxAlias";e={$mbx.alias}} # Example property from Get-Mailbox
Tee-Object
is used to save the result of the first cmdlet to the variable. The object is then being sent down the pipeline so it can be used by Get-AdPermission
.
In the Select-Object
you use calculated property and utilize the $mbx
variable you filled before.
The script won't work if Get-Mailbox
returns more than one object. In that case, both objects will be saved to the variable. As a workaround, use a loop to iterate through the array of mailboxes.
Upvotes: 2