Public/Configuration/ExchangeOnline/BitTitan/Start-BitTitanPreperation.ps1

function Start-BitTitanPreperation {
    param (
        [Parameter(Mandatory)]
        [string]$TenantId
    )

    Write-ModuleLog "Running BitTitan Preperation for $($TenantId)" -Level Info -Component 'BitTitanPreperation'
    try {
        Connect-CustomerExchange -CustomerTenantId $TenantId
        Connect-CustomerGraph -CustomerTenantId $TenantId

        $AdminAccount = Get-MgUser -Filter "startswith(UserPrincipalName,'jyskit-adm@')" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty UserPrincipalName

        if (!$AdminAccount) {
            $AdminAccount = Read-Host "Please enter the admin account to use:"
        }

        Write-ModuleLog "Adding mailbox permissions.." -Level Info -Component 'BitTitanPreperation'
        Get-Mailbox -ResultSize Unlimited | Add-MailboxPermission -AccessRights FullAccess -AutoMapping $false -User $AdminAccount -WarningAction SilentlyContinue | Out-Null

        Write-ModuleLog "Setting max send/recieve size.." -Level Info -Component 'BitTitanPreperation'
        Get-MailboxPlan | Set-MailboxPlan -MaxSendSize 150MB -MaxReceiveSize 150MB -WarningAction SilentlyContinue | Out-Null
        Get-Mailbox | Set-Mailbox -MaxReceiveSize 150MB -MaxSendSize 150MB -WarningAction SilentlyContinue | Out-Null

        Write-ModuleLog "Enabling Organization customization.." -Level Info -Component 'BitTitanPreperation'
        Enable-OrganizationCustomization -ErrorAction SilentlyContinue

        Write-ModuleLog "Disabling Focused Inbox.." -Level Info -Component 'BitTitanPreperation'
        Set-OrganizationConfig -FocusedInboxOn $false
        Get-Mailbox -ResultSize Unlimited | Set-FocusedInbox -FocusedInboxOn $false | Out-Null

        Write-ModuleLog "Disabling TNEF.." -Level Info -Component 'BitTitanPreperation'
        Get-RemoteDomain | Set-RemoteDomain -TNEFEnabled:$false -WarningAction SilentlyContinue| Out-Null

        Write-ModuleLog "Successfully ran BitTitan Preperation for $($TenantId)" -Level Info -Component 'BitTitanPreperation'
    }
    catch {
        Write-ModuleLog "Failed to run BitTitan Preperation for $($TenantId): $_" -Level Error -Component 'BitTitanPreperation' -ErrorRecord $_ -ThrowError
    }
}