How to get the Mailbox Permission of a user

Anthony K O365
Anthony K O365 used Ask the Experts™
on
I am trying to find ALL the mailboxes a particular user has access to. I'm using the following PS:
$allmbx = Get-Mailbox -ResultSize unlimited

Foreach ($mbx in $allmbx) {
Exchange 2016

      Get-MailboxPermission $_.identity -User ASmith | select identity, user, accessrights |epcsv D:\data\ASmithAccess.csv -notypeinfor
}

But I'm getting no results but I know the user has Full Access to a few mailboxes. I believe there may an issue in the 'Identity' switch. Please assist. Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Saif ShaikhServer engineer

Commented:
List all mailboxes to which a particular user has Full Access permissions:

Get-Mailbox | Get-MailboxPermission -User xyz


List all shared/user/room/whatever mailboxes to which particular user has Full Access permissions:

Get-Mailbox -RecipientTypeDetails UserMailbox,SharedMailbox -ResultSize Unlimited | Get-MailboxPermission -User xyz

List all mailboxes to which members of a particular security group have access:

Get-Mailbox | Get-MailboxPermission -User xyz

List all mailboxes to which a user has Send As permissions:

Get-Mailbox | Get-RecipientPermission -Trustee xyz

List all user mailboxes to which members of a particular security group have Send As access:

Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited | Get-RecipientPermission -Trustee xyz
Anthony K O365Messaging Consulting

Author

Commented:
Without creating a loop, this will cause the script to timeout with a limitations error. Please create while looping through all mailboxes first. thanks. This is for Exchange 2016 On-Prem

Thanks again!
Robby SwartenbroekxMSP engineer

Commented:
$allmbx = Get-Mailbox -ResultSize unlimited

Foreach ($mbx in $allmbx) {
#Exchange 2016

      Get-MailboxPermission $mbx.identity -User ASmith | select identity, user, accessrights |epcsv D:\data\ASmithAccess.csv -notypeinformation
}

Open in new window


but it's actually the same  as what Saif said, but implemented in your script with a for loop.
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Anthony K O365Messaging Consulting

Author

Commented:
Unfortunately, this only produced one mailbox, but the user i.e. 'ASmith' has access to many mailboxes. Also the accessRights column shows "Microsoft.Exchange.Management.RecipientTasks.MailboxRights [ ]"   whereas I as expecting to see 'Full Access'.  Any thoughts?
Top Expert 2014
Commented:
The code has to be adjusted so the output file isn't overwritten with each loop.  You can either use the -Append parameter of Export-CSV, or move that command outside of the loop (but be aware that the foreach statement doesn't support pipeline output).  You can surround the foreach statement with either subexpression ( $() ) or array ( @() ) notation so you can pipe the output to Export-CSV.  The AccessRights property has to be converted to a string, otherwise Export-CSV will just show the property type.
$allmbx = Get-Mailbox -ResultSize unlimited
$(Foreach ($mbx in $allmbx) {
      Get-MailboxPermission $mbx.identity -User SGrantham | select identity, user, @{n="accessrights";e={$_.accessrights}} 
}) | Export-Csv D:\data\ASmithAccess.csv -notypeinformation

Open in new window

Anthony K O365Messaging Consulting

Author

Commented:
Team,

You've all been very helpful! What a Team!!

Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial