Private/PartnerMenu/Start-PartnerMenuTenantSelection.ps1

function Start-PartnerMenuTenantSelection() {
    [Alias("back")]
    param(
        [Parameter()]
        $Tenant
    )

    if (!$Tenant -and !$Global:Tenant) {
        Get-PartnerMenuHeader -SectionString "Preparing tenant selection..."

        $Global:Tenant = Get-Tenants | Out-ConsoleGridView -Title "Select a tenant" -OutputMode Single
    }
    Clear-Host

    Get-PartnerMenuHeader -SectionString "($($Global:Tenant.displayName)) - Tenant options"

    Write-Host "[1] Connect to Exchange Online environment."
    Write-Host "[2] Connect to Microsoft Graph environment."
    Write-Host "[3] Set mailbox language/region."
    Write-Host "[4] Set calendar permissions."
    Write-Host "[5] Disable Security Defaults."
    Write-Host "[6] Create spamfilter.io Exchange Connector."
    Write-Host "[7] Create BitTitan app registration."
    Write-Host "[8] Setup Spamfilter.io."
    Write-Host "[9] Back."
    Write-Host ""
    $SelectedOption = Read-Host "Please select an option [1-8] "

    switch ($SelectedOption) {
        "1" {
            try {
                Connect-CustomerExchange -CustomerTenantId $Global:Tenant.CustomerId
                Write-Host "Connected to Exchange Online environment." -ForegroundColor Green
                Write-Host "You can always type 'back' to return to the previous menu." -ForegroundColor Yellow
            }
            catch {
                Write-Error "Failed to connect to Exchange Online: $_"
                Read-Host "Press any key to continue.."
                Start-PartnerMenuTenantSelection -Tenant $Tenant
            }
        }
        "2" {
            try {
                Connect-CustomerGraph -CustomerTenantId $Global:Tenant.CustomerId
                Write-Host "Connected to Microsoft Graph environment." -ForegroundColor Green
                Write-Host "You can always type 'back' to return to the previous menu." -ForegroundColor Yellow
            }
            catch {
                Write-Error "Failed to connect to Microsoft Graph: $_"
                Read-Host "Press any key to continue.."
                Start-PartnerMenuTenantSelection -Tenant $Tenant
            }
        }
        "3" {
            try {
                Connect-CustomerExchange -CustomerTenantId $Global:Tenant.CustomerId
                $Mailboxes = Get-EXOMailbox -ResultSize Unlimited | Where-Object { $_.Name -notlike 'Discovery*' } | Out-ConsoleGridView -Title "Select the mailboxes to set language/region for" -OutputMode Multiple
                if (($LanguageRegion = Read-Host "Which language/region do you want to set? [da-dk]") -eq '') { $LanguageRegion = "da-dk" }
                foreach ($Mailbox in $Mailboxes) {
                    Write-Host "Setting language/region to $($LanguageRegion) for $($Mailbox.UserPrincipalName)..." -ForegroundColor Cyan
                    Set-MailboxRegionalConfiguration -Identity $Mailbox -Language $LanguageRegion -LocalizeDefaultFolderName
                }
                Write-Host "Completed setting language/region to $($LanguageRegion) for $($Mailboxes.Count) mailboxes." -ForegroundColor Green
            }
            catch {
                Write-Error "Failed to set language/region: $_"
            }
            Read-Host "Press any key to continue.."
            Start-PartnerMenuTenantSelection -Tenant $Tenant
        }
        "4" {
            try {
                Connect-CustomerExchange -CustomerTenantId $Global:Tenant.CustomerId
                $Mailboxes = Get-EXOMailbox -ResultSize Unlimited | Where-Object { $_.Name -notlike 'Discovery*' } | Out-ConsoleGridView -Title "Select the mailboxes to set calendar permissions for" -OutputMode Multiple
                if (($CalendarPermission = Read-Host "Which calendar permission do you want to set? [Reviewer]") -eq '') { $LanguageRegion = "Reviewer" }
                foreach ($Mailbox in $Mailboxes) {
                    $CalendarFolder = Get-EXOMailboxFolderStatistics -Identity $Mailbox -Folderscope Calendar | Select-Object -First 1
                    Write-Host "Setting calendar permission to $($CalendarPermission) for $($Mailbox.UserPrincipalName)..." -ForegroundColor Cyan
                    Set-MailboxFolderPermission -Identity "$($Mailbox.UserPrincipalName):\$($CalendarFolder.Name)" -User Default -AccessRights $CalendarPermission
                }
                Write-Host "Completed setting calendar permission to $($CalendarPermission) for $($Mailboxes.Count) mailboxes." -ForegroundColor Green

            }
            catch {
                Write-Error "Failed to set calendar permissions: $_"
            }
            Read-Host "Press any key to continue.."
            Start-PartnerMenuTenantSelection -Tenant $Global:Tenant

        }
        "5" {
            try {
                Disable-SecurityDefaults -TenantId $Global:Tenant.CustomerId
            }
            catch {
                Write-Error "Failed to disable Security Defaults: $_"
            }
            Read-Host "Press any key to continue.."
            Start-PartnerMenuTenantSelection -Tenant $Global:Tenant
        }
        "6" {
            try {
                New-SpamfilterConnector -TenantId $Global:Tenant.CustomerId
            }
            catch {
                Write-Error "Failed to create spamfilter.io Exchange Connector: $_"
            }
            Read-Host "Press any key to continue.."
            Start-PartnerMenuTenantSelection -Tenant $Global:Tenant
        }
        "7" {
            try {
                New-BitTitanAppRegistration -TenantId $Global:Tenant.CustomerId
            } catch {
                Write-Error "Failed to create BitTitan app registration: $_"
            }
            Read-Host "Press any key to continue.."
            Start-PartnerMenuTenantSelection -Tenant $Global:Tenant
        }
        "8" {
            try {
                New-SpamfilterSetup -TenantId $Global:Tenant.CustomerId
            } catch {
                Write-Error "Failed to setup Spamfilter: $_"
            }
            Read-Host "Press any key to continue.."
            Start-PartnerMenuTenantSelection -Tenant $Global:Tenant
        }
        "9" { 
            $Global:Tenant = $null
            Start-PartnerMenu
        }
        Default {
            $Global:Tenant = $null
            Start-PartnerMenu
        }
    }

}