Help with formatting a table in Powershell

Posted on 2014-07-15
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 | `
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 | `
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            xyz\mary            xyz\bob            xyz\joe      xyz\sally      xyz\fred            xyz\joe            xyz\sally            xyz\fred            xyz\Eugene

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

$Mailboxes = get-messagetrackinglog –server ExchangeServer –sender | `
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 38

    Accepted Solution

    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 67

    Expert Comment

    Should work if you do it correct:
    get-messagetrackinglog –server ExchangeServer –sender | 
      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

    LVL 1

    Author Closing Comment

    Awesome!! Thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why do Marketing keep bothering you?

    Is your marketing department constantly asking for new email signature updates? Are they requesting a different design for every department? Do they need yet another banner added? Don’t let it get you down! There is an easy way to manage all of these requests...

    Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
    Easy CSR creation in Exchange 2007,2010 and 2013
    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…
    The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now