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 } if(!$Global:Tenant) { Start-PartnerMenu } Clear-Host $MenuItems = [ordered]@{ 1 = 'Connect to Exchange Online environment.' 2 = 'Connect to Microsoft Graph environment.' 3 = 'Set mailbox language/region.' 4 = 'Set calendar permissions.' 5 = 'Disable Security Defaults.' 6 = 'Create spamfilter.io Exchange Connector.' 7 = 'Create BitTitan app registration.' 8 = 'Setup Spamfilter.io.' 9 = 'Add a domain to the tenant.' 10 = 'Add DKIM configuration to the tenant.' 11 = 'Add DMARC configuration to the tenant.' q = 'Back' } $SelectedOption = ($MenuItems | Out-ConsoleGridView -Title "($($Global:Tenant.displayName)) - Tenant options" -OutputMode Single).Name 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" { try { Read-Host "Enter domain name to add to the tenant: " -OutVariable DomainName Add-CustomerDomain -TenantId $Global:Tenant.CustomerId -DomainName $DomainName Read-Host "Press any key to continue.." } catch { Write-Error "Failed to add domain to tenant: $_" } } 10 { try { Enable-CustomerDKIM -TenantId $Global:Tenant.CustomerId } catch { Write-Error "Failed to add DKIM configuration: $_" } Start-PartnerMenuTenantSelection -Tenant $Global:Tenant } 11 { try { Enable-CustomerDMARC -TenantId $Global:Tenant.CustomerId } catch { Write-Error "Failed to add DMARC configuration: $_" } Start-PartnerMenuTenantSelection -Tenant $Global:Tenant } "q" { $Global:Tenant = $null Start-PartnerMenu } Default { $Global:Tenant = $null Start-PartnerMenu } } } |