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

x
?
Solved

Help with formatting a table in Powershell

Posted on 2014-07-15
3
Medium Priority
?
402 Views
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:
sales@xyz.com
accounting@xyz.com
finance@xyz.com

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 `
@{n=”Mailbox”;e=”$mailbox”}
@{n=”Users”;e={$_.User}}
}
Any help with this would be greatly appreciated.

Thanks,
Nick
0
Comment
Question by:ndalmolin_13
3 Comments
 
LVL 41

Accepted Solution

by:
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

0
 
LVL 71

Expert Comment

by:Qlemo
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

0
 
LVL 1

Author Closing Comment

by:ndalmolin_13
ID: 40199698
Awesome!! Thanks.
0

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