Public/TenantConfiguration/New-BitTitanAppRegistration.ps1




function New-BitTitanAppRegistration() {
    param(
        [Parameter(Mandatory)]
        [string]$TenantId
        )
        Connect-CustomerGraph -CustomerTenantId $TenantId
        
        try {
            $AppRegistrationParams = @{
                displayName = "BitTitan MigrationWiz"
                description = "App registration for BitTitan MigrationWiz usage."
                isFallbackPublicClient = "True"
                signInAudience = "AzureADMultipleOrgs"
                publicClient = @{
                    redirectUris = @(
                        "urn:ietf:wg:oauth:2.0:oob"
                    )
                }
                requiredResourceAccess = @(
                    @{
                        resourceAppId = "00000002-0000-0ff1-ce00-000000000000"
                        resourceAccess = @(
                            @{
                                id = "3b5f3d61-589b-4a3c-a359-5dd4b5ee5bd5"
                                type = "Scope"
                            }
                        )
                    }
                )
            }
            $Application = New-MgApplication -BodyParameter $AppRegistrationParams
            Write-Host "Completed creating BitTitan app registration." -ForegroundColor Green
            $ServicePrincipal = Get-MgServicePrincipal -Filter "appId eq '$($Application.AppId)'"
            if(!$ServicePrincipal) {
                $ServicePrincipal = New-MgServicePrincipal -AppId $Application.AppId
            }
            $Resource = Get-MgServicePrincipal -Filter "appId eq '00000002-0000-0ff1-ce00-000000000000'"
            New-MgOauth2PermissionGrant -ClientId $ServicePrincipal.Id -ConsentType "AllPrincipals" -Scope "EWS.AccessAsUser.All" -ResourceId $Resource.Id
            Write-Host "Successfully granted admin consent for EWS.AccessAsUser.All." -ForegroundColor Green

            Write-Host "If enabling Modern Authentication for the source:" -ForegroundColor Cyan
            Write-Host "ModernAuthClientIdExport=$($Application.AppId)"
            Write-Host "ModernAuthTenantIdExport=$($TenantId)"
            Write-Host "If enabling modern authentication for the destination:" -ForegroundColor Cyan
            Write-Host "ModernAuthClientIdImport=$($Application.AppId)"
            Write-Host "ModernAuthTenantIdImport=$($TenantId)"
            Write-Host "Copy these values, and use them in your BitTitan project (see here: https://help.bittitan.com/hc/en-us/articles/360034124813-Authentication-Methods-for-Microsoft-365-All-Products-Migrations#h_01H9J5G42VTCP0WEED1A90DWQV) "
        } catch {
            Write-Error "Failed to create BitTitan App Registration: $_"
        }
}