Manage-Exchange-ExternalInOutlook.ps1
In
Inspect the recovered Manage-Exchange-ExternalInOutlook.ps1 script for enabling the External flag and loading sender exclusions from AllowList.txt. Its syntax and behaviour have not been validated.
Source-derived reference
These notes were recovered from OneNote. Configuration, permissions and operating results have not been freshly verified. Confirm the applicable authority and environment before acting.
Recovered script
The script is displayed as recovered reference text; syntax and behaviour have not been executed or accepted.
\<# Manage-Exchange-ExternalInOutlook
.SYNOPSIS
Script Set the Exchange Online ExternalInOutlook Email flag and update the AllowList.
.DESCRIPTION
This script gets the contents of the AllowList.txt file that MUST be in the same folder as this script when run, and updates the Exchange Online ExternalInOutlook exclusion list.
It also enables the ExternalInOutlook flag, if disabled.
.PARAMETER \<paramater Name>
There are no parameters
.EXAMPLE
.\Manage-Exchange-ExternalInOutlook.ps1"
.NOTES
To run this script you will need Exchange Admin permissions OR Pim to GA. It uses the current logged on user to connect to Exchange Online Management.
#>
# Check if the Exchange Online Management Module is installed and install if not.
if (Get-Module -Name ExchangeOnlineManagement -ListAvailable) {
Write-Host "Exchange Online PowerShell module is installed." -ForegroundColor Green
# Optional: Display the version
$moduleVersion = (Get-Module -Name ExchangeOnlineManagement -ListAvailable).Version
Write-Host "Version: $moduleVersion"
} else {
Write-Host "Exchange Online PowerShell module is not installed." -ForegroundColor Red
# Optional: Add code to install the module
Install-Module -Name ExchangeOnlineManagement -Force
}
# Remind user that script requires ExchangeOnline Admin permissions or has PIM'ed to Global Admin.
$title = "Setting Exchange Online ExternalInOutlook Flag"
$message = "This will Enable Set-ExternalInOutlook flag and update the AllowList.
Ensure you have added any new domains to the AllowList.txt file!
You must have Exchange Online Admin permissions OR you have PIM'ed to Global Admin, to change the Set-ExternalInOutlook flag!
Do you want to Proceed? "
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Performs the action"
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Aborts the script"
$options = \[System.Management.Automation.Host.ChoiceDescription\[\]\]($yes, $no)
$defaultChoice = 1 # 0 for Yes, 1 for No (default is No)
$result = $Host.UI.PromptForChoice($title, $message, $options, $defaultChoice)
switch ($result) {
0 {
Write-Host "Continuing (Yes selected)..." -ForegroundColor Green
# Code for 'Yes'
}
1 {
Write-Host "Aborting (No selected)..." -ForegroundColor Red
exit
}
}
try {
# Declare some variables, including gathering the current AllowList from the allowlist.txt file that should be in the same directory as this script.
Set-Location $PSScriptRoot
$AllowList = ((Get-Content -Path .\allowlist.txt | Where-Object { $_ -notmatch '^\s*#' -and $_ -ne ""}))
# Connect to ExchangeOnline Management
# This uses the current logged on user to connect.
Connect-ExchangeOnline -ShowBanner:$false -SkipLoadingCmdletHelp -SkipLoadingFormatData
# Then, check the connection status
$connection = Get-ConnectionInformation
if ($connection -and $connection.State -eq "Connected") {
Write-Host "Connection is active." -ForegroundColor Green
} else {
Write-Host "Connection is not active." -ForegroundColor Red
}
Set-ExternalInOutlook -Enabled $true -AllowList $AllowList
Disconnect-ExchangeOnline -Confirm:$false
}
catch {
Write-Output "Error occurred: $($_.Exception.Message)"
Write-Output "If you get the error ""A parameter cannot be found that matches parameter name 'Enabled'"" it means you don't have permission. Elevate to GA."
Write-Output "The current AllowList is " (Get-externalInOutlook).AllowList
}