####################################################### # Echoworx Setup Script for O365 Implementations ####################################################### # ############### # Version 1.0 ############### # ############################################################################ # # Written for Pax8 Partners/Customers to setup O365 for Echoworx Encryption # By Pete Link, July 2018 # ############################################################################ # # Let's create the log file variables. A new log is created each day # $date = get-date -uformat "%Y%m%d" $path = "C:\" $append = "-O365-Echoworx-Creation-Script.log" $log = "$path" + "$date" + "$append" # # Let's output some useful information about what is happending and let's start logging # Clear-Host Start-Transcript $log -Append Write-Verbose "******* Begin of run ******* on $(Get-Date) ... *******" Set-ExecutionPolicy Unrestricted -Force Sleep 5 # # Let's ensure that PowerShell environment is setup correctly # Clear-Host Write-Host Write-Host -ForegroundColor White "Ensuring that all PowerShell modules are present... Please stand by..." Write-Host Save-Module -Name MSOnline -path ./ Install-Module -Name MSOnline -SkipPublisherCheck -Force Import-module MSOnline # # Let's provide some initial overview information # sleep 5 Clear-Host Write-Host Write-Host -ForegroundColor Yellow "This script is designed to setup the O365 environment for Echoworx encryption." Write-Host -ForegroundColor Yellow "This script eliminates any manual steps that need to be done on O365 side. It is used ONLY for O365 implementations." Write-Host Write-Host -ForegroundColor Red "This script must be run by a Global Administrator." Write-Host Write-Host -ForegroundColor Red -BackgroundColor Yellow "Please enter the Global Administrator's credentials for the environment that is being setup:" Write-Host # # Press Enter to continue. Let's wait for user to press Enter before continuing. # Read-Host "Press Enter key to continue, you will be asked for your Global Admin Creds . . . or Press CTRL + c to quit" | Out-Null # # Login Process # $cred = Get-Credential Connect-MsolService -Credential $cred $ex = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell -Credential $cred -Authentication basic -AllowRedirection Import-PSSession $ex -AllowClobber #Clear-Host Write-Host Write-Host -ForegroundColor Yellow "Verifying that $($cred.Username) is a Global Administrator... This script would have aborted if this test were to fail..." Write-Host # # Let's verify that the user who logged on is a Global Administrator # $admins = Get-MsolRoleMember -RoleObjectId ((Get-MsolRole -RoleName "Company Administrator").ObjectId) if ($admins.EmailAddress -contains $cred.UserName) {"$($cred.Username) is a Global Administrator"} Else {"$($cred.UserName) is NOT a Global Administrator. CAN NOT Continue... Exiting..."; Write-Host -ForegroundColor Red "Please re-run the script and logon as a Global Administrator"; Write-Host -ForegroundColor White "No changes were made to the environment";exit} Write-Host # ####################################################### # # The key work happens in the section below # ####################################################### # # Let's create the Outbound Connector # New-OutboundConnector -name 'OneWorld SaaS Email Encryption' -ConnectorType Partner -Enabled $true -Comment "Connector to Echoworx for email encryption" -IsTransportRuleScoped $true -SmartHosts smtp.mobilencrypt.com -UseMXRecord $false -TlsSettings CertificateValidation # # Let's Validate the Outbound Connector # Sleep 5 Write-Host Write-Host -ForegroundColor Yellow 'The next step is to enter the email address to receive the validation email.' Write-Host -ForegroundColor Yellow 'NOTE: This email must NOT be part of the Domain that is being setup.' Write-Host $recipient = Read-Host -Prompt 'Input the email address that will receive the validation email' Validate-OutboundConnector -Identity 'OneWorld SaaS Email Encryption' -Recipients $recipient -Confirm:$true # # Let's set the Connector to Validated # $date = Get-Date Set-OutboundConnector -Identity 'OneWorld SaaS Email Encryption' -IsValidated $true -LastValidationTimestamp $date -ValidationRecipients $recipient # # Let's create the First Transport Rule to encrypt based on Keyword in Subject. Please note the Priority Level is set to 0 and 1 respectively. New-TransportRule -Name 'Encrypt on Keyword in Subject' -Priority 0 -Enabled $true -SubjectContainsWords encrypt: -RouteMessageOutboundConnector 'OneWorld SaaS Email Encryption' -ExceptIfSentToScope InOrganization New-TransportRule -Name 'Create Office 365 Mail Flow Rule-Sender used Encrypt Button' -Priority 1 -Enabled $true -HeaderContainsMessageHeader x-echoworx-encrypt -HeaderContainsWords yes -RouteMessageOutboundConnector 'OneWorld SaaS Email Encryption' -ExceptIfSentToScope InOrganization # ####################################################### # # End of key section # ####################################################### # # Logout from the environment and close session # Remove-PSSession $ex Write-Host Write-Host -ForegroundColor Yellow "The setup has been completed." Write-Host Write-Host -ForegroundColor Yellow "Check to ensure that you received the validation email." Write-Host Write-Host Write-Host -ForegroundColor Red "Please Test encryption:" Write-Host -ForegroundColor Yellow '1. Test encryption using the keyword "encrypt:" in the subject.' Write-Host -ForegroundColor Yellow '2. Test encryption using x-headers by utilizing the Outlook Plug-in.' Write-Host Write-Host -ForegroundColor White 'To exit this session; simply type the word exit' # Write-Verbose "******* End of run ******* on $(Get-Date) *******" Write-Host Stop-Transcript # ####################################################### # #Other Helpful Commands: # ####################################################### # #Get-ExecutionPolicy #Set-ExecutionPolicy Unrestricted # #Get-TransportRule #Get-OutboundConnector #