Shared Mailbox Management

This scripts below can be useful in managing O365 Shared Mailboxes using Powershell.

NOTE: You need to have an existing O365 PSSession. To connect to an O365 PSSession, check my other article for Connecting to Exchange Online PS Session


Getting Attributes of Shared Mailbox

Param (
    [Parameter(Mandatory=$True)]
    [string]$365SharedMailboxIdentity
)

$details = Get-Mailbox -identity $365SharedMailboxIdentity `
|Select-Object IsShared,Alias,Name,Identity,Displayname,PrimarySmtpAddress,UserPrincipalName, `
WhenMailboxCreated,RecipientType,AccountDisabled,UsageLocation,HiddenFromAddressListsEnabled, `
MaxReceiveSize,MaxSendSize,AuditLogAgeLimit,AuditEnabled,ArchiveWarningQuota,ArchiveQuota, `
ProhibitSendQuota,ProhibitSendReceiveQuota,RecoverableItemsQuota,RecoverableItemsWarningQuota

$permission = Get-MailboxPermission -identity $365SharedMailboxIdentity | ft user,accessrights

#OUTPUT
echo "====== ===== ===== ======"
echo "*  MAILBOX PROPERTIES  *"
echo ""
echo "Is Shared Mailbox: $($details.IsShared)"
echo "Alias: $($details.Alias)"
echo "Name: $($details.Name)"
echo "Identity: $($details.Identity)"
echo "Display Name: $($details.DisplayName)"
echo "Email Addresses: $($details.PrimarySmtpAddress)"
echo "UserPrincipalName: $($details.UserPrincipalName)"
echo "Hidden From Address Book: $($details.HiddenFromAddressListsEnabled)"
echo ""
echo "====== ===== ===== ======"
echo "*  ACCOUNT PROPERTIES  *"
echo ""
echo "Creation Date: $($details.WhenMailboxCreated)"
echo "RecipientType: $($details.RecipientType)"
echo "Disabled: $($details.AccountDisabled)"
echo "UsageLocation: $($details.UsageLocation)"
echo "Audit Log Enabled: $($details.AuditEnabled)"
echo "Audit Log Retention in Days: $($details.AuditLogAgeLimit)"
echo ""
echo "====== ===== ===== ======"
echo "*  MAILBOX LIMITATIONS  *"
echo ""
echo "MaxReceiveSize: $($details.MaxReceiveSize)"
echo "MaxSendSize: $($details.MaxSendSize)"
echo "Archiving Quota Warning in GB: $($details.ArchiveWarningQuota)"
echo "Archiving Quota in GB: $($details.ArchiveQuota)"
echo "User Will not be able to send if mailbox size is more than: $($details.ProhibitSendQuota)"
echo "User Will not be able to send and receive if mailbox size is more than: $($details.ProhibitSendReceiveQuota )"
echo "Recoverable Items Quota Warning in GB: $($details.RecoverableItemsWarningQuota)"
echo "Recoverable Items Quota in GB: $($details.RecoverableItemsQuota)"
echo ""
echo "====== ===== ===== ======"
echo "*  MAILBOX DELEGATION  *"
echo ""
echo $permission
echo "====== END OF OUTPUT ======"

Download this script from Github.


Getting Delegated Users of Shared Mailbox


Param (
    [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
    [AllowEmptyString()]
    [string]$sharedMailbox_Alias
    )

$result1 = Get-MailboxPermission -Identity $sharedMailbox_Alias | ft identity,user,accessrights | Out-String
$result2 = $result1.Split([Environment]::NewLine)

Echo "============= DELEGATED USERS ============="
foreach($x in $result2){
    if($x -like "*@*"){
    echo $x
    }
}
Echo "============= END OF RESULT ============="

Download this script from Github.


Getting the Sent Items Config for Delegates of Shared Mailbox

Param (
    [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
    [AllowEmptyString()]
    [string]$sharedmailbox_with_domain
    )


set-mailbox $sharedmailbox_with_domain -MessageCopyForSentAsEnabled $True -Force
set-mailbox $sharedmailbox_with_domain -MessageCopyForSendOnBehalfEnabled $True -Force

$result = Get-Mailbox $sharedmailbox_with_domain |select-object Alias,PrimarySMTPAddress,MessageCopyForSentAsEnabled,MessageCopyForSendOnBehalfEnabled

echo "==================================================="
echo ""
echo "Getting Sent Items Config for $sharedmailbox_with_domain"
echo "Alias: $($result.Alias)"
echo "Email Address: $($result.PrimarySMTPAddress)"
echo "Allow Send As delegates to send emails to their sent items: $($result.MessageCopyForSentAsEnabled)"
echo "Allow Send On Behalf delegates to send emails to their sent items: $($result.MessageCopyForSendOnBehalfEnabled)"
echo ""
echo "==================================================="


Download this script from Github.


Adding Delegates for a Shared Mailbox

Param (
    [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
    [AllowEmptyString()]
    [string]$sharedmailbox_with_domain,
    [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
    [AllowEmptyString()]
	[string]$delegate_with_domain
    )


Get-Mailbox -identity $sharedmailbox_with_domain | `
Add-MailboxPermission -User $delegate_with_domain -AccessRights FullAccess -InheritanceType all -AutoMapping $True

$result1 = Get-MailboxPermission -Identity $sharedmailbox_with_domain | ft identity,user,accessrights | Out-String
$result2 = $result1.Split([Environment]::NewLine)

Echo "============= DELEGATED USERS ============="
foreach($x in $result2){

    if($x -like "*@*"){
        if($x -like "*$delegate_with_domain*"){
        echo $($x +">>> *** NEWLY ADDED ***")
        }
        else{ echo $x }
    }
    }

Echo "============= END OF RESULT ============="

Download this script from Github.


Removal of Shared Mailbox Delegation

Param (
    [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
    [AllowEmptyString()]
    [string]$sharedmailbox_with_domain,
    [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
    [AllowEmptyString()]
	[string]$delegate_with_domain
    )

$result1 = Get-MailboxPermission -Identity $sharedmailbox_with_domain | ft identity,user,accessrights | Out-String
$result2 = $result1.Split([Environment]::NewLine)

Echo "============= DELEGATED USERS BEFORE REMOVAL ============="
    foreach($x in $result2){
        if($x -like "*@*"){echo $x}
    }

Echo "============= END OF DELEGATED USERS BEFORE REMOVAL ============="
echo ""
echo "... ... ... REMOVING DELEGATION ... ... ... "
echo ""

Get-Mailbox -identity $($shared+"@concentrix.com") | `
remove-MailboxPermission -User $($delegate+"@concentrix.com") -AccessRights FullAccess

$result1 = Get-MailboxPermission -Identity $sharedmailbox_with_domain | ft identity,user,accessrights | Out-String
$result2 = $result1.Split([Environment]::NewLine)

Echo "============= DELEGATED USERS AFTER REMOVAL ============="
    foreach($x in $result2){
        if($x -like "*@*"){echo $x}
    }

Echo "============= END OF ELEGATED USERS AFTER REMOVAL ============="


Download this script from Github.