Skip to content

Instantly share code, notes, and snippets.

@systemautomater
Created October 1, 2017 21:01
Show Gist options
  • Save systemautomater/24dae287abf5240832fa45dbac986857 to your computer and use it in GitHub Desktop.
Save systemautomater/24dae287abf5240832fa45dbac986857 to your computer and use it in GitHub Desktop.
#Obtain user credentials and connect to Exchange Online and import session commandlets
$userCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $userCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
#Display summary message of the function of the script
Write-Host "This script will change the setting on a shared mailbox in Exchange Online for Office 365 to enable copies of mail sent from a shared mailbox by a user to be place in the SENT folder of the shared mailbox for compliance. By default this setting is disabled and the only copy of the sent message is stored in the sending users personal mailbox SENT folder."
#space for asthetics and to reduce clutter during reading
Write-Host " "
#user prompt to continue
Read-Host "Press ENTER after you have read the above information"
#obtain mailbox input for mailbox to be configured from user
$mailbox = Read-Host "Enter the email address for the shared mailbox you would like to edit and press ENTER (Example: jsnuffy@xyzcompany.com)"
#retrive mailbox information and display current setting configuration for this specific setting
Get-Mailbox $mailbox | Select Name, MessageCopyForSentAsEnabled, MessageCopyForSendOnBehalfEnabled | fl
#prompt user to validate they would like to make the change
$answer = Read-Host "Would you like to Enable or Disable the copy of mail setting for the specified mailbox? (enable/disable)"
#if enable was entered enable setting on mailbox
If($answer -eq "enable"){
Set-Mailbox $mailbox -MessageCopyForSentAsEnabled $true
Set-Mailbox $mailbox -MessageCopyForSendOnBehalfEnabled $true
Write-Host "Message copies have been enabled on this mailbox!"
Get-Mailbox $mailbox | Select Name, MessageCopyForSentAsEnabled, MessageCopyForSendOnBehalfEnabled | fl
}
#if disable was entered disable setting on mailbox
If($answer -eq "disable"){
Set-Mailbox $mailbox -MessageCopyForSentAsEnabled $false
Set-Mailbox $mailbox -MessageCopyForSendOnBehalfEnabled $false
Write-Host "Message copies have been disabled on this mailbox!"
Get-Mailbox $mailbox | Select Name, MessageCopyForSentAsEnabled, MessageCopyForSendOnBehalfEnabled | fl
}
#if anything other than enable or disable was entered notify user to rerun the script and enter the correct option
If($answer -ne "enable","disable"){
Write-Host "The input you entered was not recognized. Please rerun the script and enter either enable or disable to choose the setting configuration."
Exit
}
#disconnect PSSession
Remove-PSSession $Session
#prompt user to acknowledge completion of script before exit
Write-Host "Press enter to exit the script."
Pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment