Manage Sent Items
Enable/Disable copying sent items to shared or delegated mailboxes.
By default, when a user sends email as a shared or delegated mailbox, the sent item is only saved to the trustee's Sent Items folder. This makes tracking sent items from the shared/delegated mailbox more difficult, as there is no longer a single location to see all items sent by that mailbox.
The Microsoft 365 Admin Center has options in the UI to enable copying items sent as the shared mailbox, or on behalf of it, to the shared mailbox's Sent Items folder.
Unfortunately, these options don't exist in the UI for delegated user mailboxes, but they can be enabled via the ExchangeOnlineManagement PowerShell module. This lets shared/delegated mailbox users see the email other members have sent.
In order to run this script, you will need:
- Global Admin credentials for the Microsoft tenant that contains the mailbox
- The email address of the delegated/shared mailbox
- The ability to run PowerShell as admin on your local machine
The below script will enable copying items sent as the delegated mailbox, or on behalf of it, to the delegated mailbox's Sent Items folder. It will also work for shared mailboxes.
To disable copying sent items, use the
-Disable
switch.Usage:
powershell -ExecutionPolicy Bypass -File .\ManageSentItems.ps1 -Address [email protected]
# Manage Sent Item Settings
param(
[Parameter(Mandatory = $true)]
[MailAddress]$Address, # User/shared email address ([email protected])
[Switch]$Disable # Disable message copy for sent items
)
[String]$Address = $Address
if ($Disable) { $ModifyBoolean = $false } else { $ModifyBoolean = $true }
$Modules = @('ExchangeOnlineManagement')
$ErrorActionPreference = 'Stop'
function Install-PSModule {
param(
[Parameter(Position = 0, Mandatory = $true)]
[String[]]$Modules
)
Write-Output "`nChecking for necessary PowerShell modules..."
try {
# Set PowerShell to TLS 1.2 (https://devblogs.microsoft.com/powershell/powershell-gallery-tls-support/)
if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12' -and [Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls13') {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
}
# Install NuGet package provider
if (!(Get-PackageProvider -ListAvailable -Name 'NuGet' -ErrorAction Ignore)) {
Write-Output 'Installing NuGet package provider...'
Install-PackageProvider -Name 'NuGet' -MinimumVersion 2.8.5.201 -Force
}
# Set PSGallery to trusted repository
Register-PSRepository -Default -InstallationPolicy 'Trusted' -ErrorAction Ignore
if (!(Get-PSRepository -Name 'PSGallery' -ErrorAction Ignore).InstallationPolicy -eq 'Trusted') {
Set-PSRepository -Name 'PSGallery' -InstallationPolicy 'Trusted'
}
# Install & import modules
ForEach ($Module in $Modules) {
if (!(Get-Module -ListAvailable -Name $Module -ErrorAction Ignore)) {
Write-Output "`nInstalling $Module module..."
Install-Module -Name $Module -Force
Import-Module $Module
}
}
Write-Output 'Modules installed successfully.'
}
catch {
Write-Warning 'Unable to install modules.'
Write-Warning $_
exit 1
}
}
# Check if script was run interactively
$IsInteractive = [Environment]::UserInteractive
if (!$IsInteractive) {
Write-Warning 'This script was designed to be run interactively. Aborting...'
exit 1
}
# Connect to Exchange Online
try {
Install-PSModule -Modules $Modules
Connect-ExchangeOnline
}
catch {
Write-Warning 'Unable to connect to Exchange Online.'
Write-Warning $_
if ($IsInteractive) { Read-Host -Prompt 'Press Enter to exit' }
exit 1
}
# Modify message copy for sent items
try {
Write-Output "Modifying message copy for sent items: [$Address]"
Set-Mailbox $Address -MessageCopyForSentAsEnabled $ModifyBoolean
Set-Mailbox $Address -MessageCopyForSendOnBehalfEnabled $ModifyBoolean
Get-Mailbox $Address | Format-List -Property 'MessageCopyForSentAsEnabled', 'MessageCopyForSendOnBehalfEnabled'
}
catch {
Write-Warning "There was an error modifying message copy for sent items: [$Address]"
Write-Warning $_
Get-Mailbox $Address | Format-List -Property 'MessageCopyForSentAsEnabled', 'MessageCopyForSendOnBehalfEnabled'
Disconnect-ExchangeOnline -Confirm:$false
if ($IsInteractive) { Read-Host -Prompt 'Press Enter to exit' }
exit 1
}
Disconnect-ExchangeOnline -Confirm:$false
if ($IsInteractive) { Read-Host -Prompt 'Press Enter to exit' }
Last modified 6mo ago