logo exchange

Overzicht mailbox rechten

Voor Exchange Server

# Add Exchange snap-in if not already loaded
if (!(Get-PSSnapin | Where-Object { $_.Name -eq "Microsoft.Exchange.Management.PowerShell.SnapIn" })) {
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
}

# Get all user mailboxes
$mailboxes = Get-Mailbox -ResultSize Unlimited

# Create an empty array to store results
$results = @()

foreach ($mailbox in $mailboxes) {
    $mailboxPermissions = Get-MailboxPermission -Identity $mailbox.Identity

    # Loop through all permissions for each mailbox
    foreach ($permission in $mailboxPermissions) {
        $result = New-Object PSObject -Property @{
            "Mailbox" = $mailbox.DisplayName
            "User" = $permission.User
            "AccessRights" = $permission.AccessRights
        }
        $results += $result
    }
}

# Output results to a log file
$results | Format-Table -AutoSize | Out-File -FilePath "C:\beheer\mailboxrights.log"

Voor Exchange Online

# Connect to Exchange Online PowerShell
# Ensure you have the required permissions to run this script
# Install the necessary modules if not already installed
# Install-Module -Name ExchangeOnlineManagement

# Authenticate to Exchange Online
Connect-ExchangeOnline -UserPrincipalName yourAdminUPN@yourdomain.com -ShowProgress $true

# Get all mailboxes
$mailboxes = Get-Mailbox -ResultSize Unlimited

# Create an empty array to store results
$results = @()

foreach ($mailbox in $mailboxes) {
    $mailboxPermissions = Get-MailboxPermission -Identity $mailbox.Identity

    # Loop through all permissions for each mailbox
    foreach ($permission in $mailboxPermissions) {
        $result = New-Object PSObject -Property @{
            "Mailbox" = $mailbox.DisplayName
            "User" = $permission.User
            "AccessRights" = $permission.AccessRights
        }
        $results += $result
    }
}

# Output results to a log file
$results | Format-Table -AutoSize | Out-File -FilePath "C:\beheer\mailboxrights_online.log"

# Disconnect from Exchange Online session
Disconnect-ExchangeOnline -Confirm:$false