Use the command below in PowerShell
<Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited | Get-MailboxPermission | select identity,user,accessrights | where { ($_.User -like '*@*') }>
More advanced version
To ensure that shared mailboxes without any assigned users are included in your output, always return the mailbox information, even if there are no permissions assigned.
Get-Mailbox -RecipientTypeDetails SharedMailbox -ResultSize Unlimited | ForEach-Object {
$mailbox = $_
$permissions = Get-MailboxPermission -Identity $mailbox.Identity -ErrorAction SilentlyContinue |
Where-Object { $_.User -like '*@*' } |
Select-Object User, AccessRights
# Create a custom object to include mailbox info and permissions
[PSCustomObject]@{
WindowsEmailAddress = $mailbox.WindowsEmailAddress
User = if ($permissions) { $permissions.User -join ', ' } else { 'No Users Assigned' }
AccessRights = if ($permissions) { $permissions.AccessRights -join ', ' } else { 'No Access Rights' }
}
} | Export-Csv -Path "C:\Path\To\Your\SharedMailboxesPermissions.csv" -NoTypeInformation
Explanation:
- Get-Mailbox: Retrieves all shared mailboxes.
- ForEach-Object: Loops through each mailbox.
- Get-MailboxPermission: Attempts to get permissions for each mailbox, using
-ErrorAction SilentlyContinue
to suppress errors if the mailbox cannot be found. - Custom Object: Creates a custom object for each mailbox:
- WindowsEmailAddress: Always included.
- User: If permissions exist, it joins the user names; otherwise, it indicates "No Users Assigned."
- AccessRights: Similar logic for access rights.
- Export-Csv: Exports the results to a CSV file.
Notes:
- Replace
"C:\Path\To\Your\SharedMailboxesPermissions.csv"
with your desired file path. - This approach ensures that all shared mailboxes are included in the output, regardless of whether they have assigned users.
If you have any further questions or need additional adjustments, feel free to ask!
No comments:
Post a Comment