Install ADFS on Azure VM step by step

[Powershell Script] Genrate report to get Mailboxes a user has access to. [Powershell Tips] How to use Group-Object in Powershell.

how to get report on what mailboxes a user has permissions?

Some time back I was asked to generate Mailbox Access report based on user, where we wanted report on what mailboxes a user has access too.

Below I 'll be demonstrating how can we use Group-Object in PowerShell to achieve the same.

At this time we have Get-MailboxAccess CMD which will return the users who has access to that mailbox, so to get the desired report we will run the Get-MailboxAccess Report on all the desired Mailbox, and then we will use the Group-Object to group them by user, that will get the desired report.

NOTE: This script below has been build for Exchange 2010, there may be some little modification needed when running for Office365.

First get all the Shared Mailbox or the Mailboxes you wish to get report on.

"Getting All Shared Mailboxes..."
$Allmailbox = Get-Mailbox -ResultSize unlimited -RecipientTypeDetails sharedMailbox

Then Run Get-MailboxPermssions for Each Mailbox


$MailboxPermissions=@()
foreach($Mailbox in $AllMailbox) {
$prm=Get-MailboxPermission -Identity $Mailbox.alias
$MailboxPermissions+=$prm
}

Add your filters to remove the unwanted entries.


$FilteredPermissions = $MailboxPermissions | ? {$_.User -Notlike "NT AUTHORITY*" -and `
$_.User -Notlike "S-1-5-21*" -and $_.IsInherited -ne "True"}

$postfilter = $FilteredPermissions | select Identity,User,AccessRights

Next we will Group the results in $postFilters by Group-Object


"Grouping by User.."

$Grouped = $postfilter | group User

now we have Grouped the permissions by Users so next we just need to rearrange them in $report array to so we export them to a csv.


$Report=@()

foreach ($entry in $Grouped){
$Report+=$entry.Group
}

$Report | select User,Identity, {$_.AccessRights} | Export-Csv "FullMailboxReport-Multi.csv" -NoTypeIn

Isn't that cool to use the Group-Object to manipulate the data in PowerShell.

I hope you find it informative and useful, please feel fee to give your feedback and suggests in comment section.

Comments