[Webinar] Learn how to a build a cloud-first strategyRegister Now


Help with formatting a table in Powershell

Posted on 2014-07-15
Medium Priority
Last Modified: 2014-07-16
Hello PowerShell Experts
I need a little help with formatting a table.  I have the following command that queries Exchange for mailboxes that received an email from a specific address.
$Mailboxes = get-messagetrackinglog –server ExchangeServer –sender nick@domain.com | `
where-object {$_.eventid –eq “deliver” }| select –expandproperty recipients

This produces the following list:

Now I want to find out who has access to these mailboxes, so I do the following:

$Mailboxes = get-messagetrackinglog –server ExchangeServer –sender nick@domain.com | `
where-object {$_.eventid –eq “deliver”} | select –expandproperty recipients

Foreach ($mailbox in $mailboxes) {
      Get-mailboxpermission $mailbox | select User

This gives me a list of users for each mailbox.  

I would like to create a table with this information.  The table would look like:

Mailbox                  User
sales@xyz.com            xyz\mary
sales@xyz.com            xyz\bob
sales@xyz.com            xyz\joe
accounting@xyz.com      xyz\sally
accounting@xyz.com      xyz\fred
finance@xyz.com            xyz\joe
finance@xyz.com            xyz\sally
finance@xyz.com            xyz\fred
finance@xyz.com            xyz\Eugene

My thoughts were something like this, but this isn’t working:

$Mailboxes = get-messagetrackinglog –server ExchangeServer –sender nick@domain.com | `
where-object {$_.eventid –eq “deliver”} | select –expandproperty recipients

Foreach ($mailbox in $mailboxes) {
      Get-mailboxpermission $mailbox | select `
Any help with this would be greatly appreciated.

Question by:ndalmolin_13
LVL 41

Accepted Solution

footech earned 2000 total points
ID: 40198272
You're close.  Your first calculated property doesn't have braces around the expression.  The second is only needed if you want to change the property name from "User" to "Users".
Foreach ($mailbox in $mailboxes) {
       Get-mailboxpermission $mailbox | Select @{n="Mailbox";e={$mailbox}},User

Open in new window

LVL 71

Expert Comment

ID: 40198288
Should work if you do it correct:
get-messagetrackinglog –server ExchangeServer –sender nick@domain.com | 
  where-object {$_.eventid –eq “deliver”} |
  select –expandproperty recipients | % {
      $mailbox = $_
      Get-MailboxPermission $mailbox | select 
        @{n=”Mailbox”; e={$mailbox}},
        @{n=”Users”;  e={$_.User}}

Open in new window


Author Closing Comment

ID: 40199698
Awesome!! Thanks.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
Stellar Exchange Toolkit: this 5 in 1 toolkit comes loaded with mega-software tool. Here’s an introduction to tools’ usage and advantages:
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question