Repository: microsoft/CSS-Exchange
File: M365/MDO/ResendFailedMail.ps1 (PowerShell)

Code before:
    [Parameter(Mandatory = $true, ParameterSetName = "ScriptUpdateOnly")]
    [switch]$ScriptUpdateOnly
)

. $PSScriptRoot\..\..\Shared\ScriptUpdateFunctions\Test-ScriptVersion.ps1
. $PSScriptRoot\..\..\Shared\LoggerFunctions.ps1
. $PSScriptRoot\..\..\Shared\OutputOverrides\Write-Host.ps1
. $PSScriptRoot\..\..\Shared\OutputOverrides\Write-Progress.ps1
. $PSScriptRoot\..\..\Shared\OutputOverrides\Write-Verbose.ps1
. $PSScriptRoot\..\..\Shared\OutputOverrides\Write-Warning.ps1

$recipientCache = @{}

function Write-DebugLog ($message) {
    if (![string]::IsNullOrEmpty($message)) {
        $Script:DebugLogger = $Script:DebugLogger | Write-LoggerInstance $message
    }
}

function Write-HostLog ($message) {
    if (![string]::IsNullOrEmpty($message)) {
        $Script:HostLogger = $Script:HostLogger | Write-LoggerInstance $message
    }
    # all write-host should be logged in the debug log as well.
    Write-DebugLog $message
}

$LogFileName = "ResendFailedMail"
$StartDate = Get-Date
$StartDateFormatted = ($StartDate).ToString("yyyyMMddhhmmss")
$Script:DebugLogger = Get-NewLoggerInstance -LogName "$LogFileName-Debug-$StartDateFormatted" -LogDirectory $PSScriptRoot -AppendDateTimeToFileName $false -ErrorAction SilentlyContinue
$Script:HostLogger = Get-NewLoggerInstance -LogName "$LogFileName-Results-$StartDateFormatted" -LogDirectory $PSScriptRoot -AppendDateTimeToFileName $false -ErrorAction SilentlyContinue
SetWriteHostAction ${Function:Write-HostLog}
SetWriteProgressAction ${Function:Write-DebugLog}
SetWriteVerboseAction ${Function:Write-DebugLog}
SetWriteWarningAction ${Function:Write-HostLog}

$BuildVersion = ""

Write-Host ("ResendFailedMail.ps1 script version $($BuildVersion)") -ForegroundColor Green

if ($ScriptUpdateOnly) {
    switch (Test-ScriptVersion -AutoUpdate -VersionsUrl "https://aka.ms/ResendFailedMail-VersionsURL" -Confirm:$false) {
        ($true) { Write-Host ("Script was successfully updated.") -ForegroundColor Green }
        ($false) { Write-Host ("No update of the script performed.") -ForegroundColor Yellow }
        default { Write-Host ("Unable to perform ScriptUpdateOnly operation.") -ForegroundColor Red }
    }
    return
}

if ((-not($SkipVersionCheck)) -and (Test-ScriptVersion -AutoUpdate -VersionsUrl "https://aka.ms/ResendFailedMail-VersionsURL" -Confirm:$false)) {

Review comment (suggestion):
I would consider using this here: https://github.com/microsoft/CSS-Exchange/blob/main/Shared/GenericScriptStartLogging.ps1

And this: https://github.com/microsoft/CSS-Exchange/blob/main/Shared/ScriptUpdateFunctions/GenericScriptUpdate.ps1

Code after:
    [DateTime]$EndDate,
    [Parameter(Mandatory = $false, ParameterSetName = "ResendCopyFailedDays")]
    [ValidateRange(1, 10)]
    [Int16]$Days,
    [Parameter(Mandatory = $false, ParameterSetName = "ResendCopyFailed")]
    [Parameter(Mandatory = $false, ParameterSetName = "ResendCopyFailedDays")]
    [switch]$SkipConnectionCheck,
    [Parameter(Mandatory = $false, ParameterSetName = "ResendCopyFailed")]
    [Parameter(Mandatory = $false, ParameterSetName = "ResendCopyFailedDays")]
    [switch]$SkipVersionCheck,
    [Parameter(Mandatory = $true, ParameterSetName = "ScriptUpdateOnly")]
    [switch]$ScriptUpdateOnly
)

$Script:DualLoggingEnabled = $true
. $PSScriptRoot\..\..\Shared\GenericScriptStartLogging.ps1

$versionsUrl = "https://aka.ms/ResendFailedMail-VersionsURL"
. $PSScriptRoot\..\..\Shared\ScriptUpdateFunctions\GenericScriptUpdate.ps1

$recipientCache = @{}

Write-Verbose "Url to check for new versions of the script is: $versionsUrl"

function Test-GraphContext {
    [OutputType([bool])]
    param (
        [Parameter(Mandatory = $true)]
        [string[]]$Scopes,
        [Parameter(Mandatory = $true)]
        [string[]]$ExpectedScopes
    )

    $validScope = $true
    foreach ($expectedScope in $ExpectedScopes) {
        if ($Scopes -contains $expectedScope) {
            Write-Verbose "Scopes $expectedScope is present."
        } else {
            Write-Host "The following scope is missing: $expectedScope" -ForegroundColor Red
            $validScope = $false
        }
    }
    return $validScope
}

if (-not $SkipConnectionCheck) {
    #Validate EXO PS Connection
    $exoConnection = $null
    try {
        $exoConnection = Get-ConnectionInformation -ErrorAction Stop
    } catch {