From 43972205379125d68fec27066caf62cdf91770c7 Mon Sep 17 00:00:00 2001 From: AdminDroid <49208841+admindroid-community@users.noreply.github.com> Date: Fri, 27 Mar 2020 17:36:03 +0530 Subject: [PATCH] External Warning for Office 365 External Emails This script will prepend 'External' in subject and add 'Disclaimer' for external emails. --- .../ExternalWarningRule.ps1 | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 External Warning Rule for External Emails/ExternalWarningRule.ps1 diff --git a/External Warning Rule for External Emails/ExternalWarningRule.ps1 b/External Warning Rule for External Emails/ExternalWarningRule.ps1 new file mode 100644 index 0000000..17b8678 --- /dev/null +++ b/External Warning Rule for External Emails/ExternalWarningRule.ps1 @@ -0,0 +1,112 @@ +#Create mail flow rule for adding External warning message for external mails +Param +( + [Parameter(Mandatory = $false)] + [switch]$MFA, + [string]$ExcludeGroupMembers, + [string]$ExcludeMB, + [string]$UserName, + [string]$Password +) +Get-PSSession | Remove-PSSession +#Authentication using MFA +if($MFA.IsPresent) +{ + $MFAExchangeModule = ((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1) + If ($MFAExchangeModule -eq $null) + { + Write-Host `nPlease install Exchange Online MFA Module. -ForegroundColor yellow + Write-Host You can manually install module using below blog : `nhttps://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/ `nOR you can install module directly by entering "Y"`n + $Confirm= Read-Host `nAre you sure you want to install module directly? [Y] Yes [N] No + if($Confirm -match "[Y]") + { + Start-Process "iexplore.exe" "https://cmdletpswmodule.blob.core.windows.net/exopsmodule/Microsoft.Online.CSE.PSModule.Client.application" + } + else + { + Start-Process 'https://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/' + Exit + } + $Confirmation= Read-Host Have you installed Exchange Online MFA Module? [Y] Yes [N] No + if($Confirmation -match "[yY]") + { + $MFAExchangeModule = ((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter CreateExoPSSession.ps1 -Recurse ).FullName | Select-Object -Last 1) + If ($MFAExchangeModule -eq $null) + { + Write-Host Exchange Online MFA module is not available -ForegroundColor red + Exit + } + } + else + { + Write-Host Exchange Online PowerShell Module is required + Start-Process 'https://o365reports.com/2019/04/17/connect-exchange-online-using-mfa/' + Exit + } + } + + #Importing Exchange MFA Module + . "$MFAExchangeModule" + Write-Host Enter credential in prompt to connect to Exchange Online + Connect-EXOPSSession -WarningAction SilentlyContinue +} + +#Authentication using non-MFA +else +{ + #Storing credential in script for scheduling purpose/ Passing credential as parameter + if(($UserName -ne "") -and ($Password -ne "")) + { + $SecuredPassword = ConvertTo-SecureString -AsPlainText $Password -Force + $Credential = New-Object System.Management.Automation.PSCredential $UserName,$SecuredPassword + } + else + { + $Credential=Get-Credential -Credential $null + } + $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection -WarningAction SilentlyContinue + Import-PSSession $Session -AllowClobber -DisableNameChecking | Out-Null +} +$Disclaimer='