Public/Shared/Start-BitTitanPreperation.ps1

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

    Clear-Host
    Write-Host "Running BitTitan Preperation for $($TenantId)" -ForegroundColor Cyan
    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-Host "Adding mailbox permissions.." -ForegroundColor Yellow
        Get-Mailbox -ResultSize Unlimited | Add-MailboxPermission -AccessRights FullAccess -AutoMapping $false -User $AdminAccount -WarningAction SilentlyContinue | Out-Null

        Write-Host "Setting max send/recieve size.." -ForegroundColor Yellow
        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-Host "Enabling Organization customization.." -ForegroundColor Yellow
        Enable-OrganizationCustomization -ErrorAction SilentlyContinue

        Write-Host "Disabling Focused Inbox.." -ForegroundColor Yellow
        Set-OrganizationConfig -FocusedInboxOn $false
        Get-Mailbox -ResultSize Unlimited | Set-FocusedInbox -FocusedInboxOn $false | Out-Null

        Write-Host "Disabling TNEF.." -ForegroundColor Yellow
        Get-RemoteDomain | Set-RemoteDomain -TNEFEnabled:$false -WarningAction SilentlyContinue| Out-Null

        Write-Host "Successfully ran BitTitan Preperation for $($TenantId)" -ForegroundColor Green
    }
    catch {
        throw "Failed to run BitTitan Preperation $($TenantId): $_"
    }
}