Public/TenantConfiguration/Baseline/Add-MobileThreatDefenseConnectors.ps1

function Add-MobileThreatDefenseConnectors {
    param(
        [Parameter(Mandatory)]
        [string]$TenantId
    )

    try {
        Connect-CustomerGraph -CustomerTenantId $TenantId

        $MobileThreatDefenseConnectors = (Invoke-GraphRequest -Method GET -Uri "https://graph.microsoft.com/beta/deviceManagement/mobileThreatDefenseConnectors").value

        $MobileThreatDefenseConnectorsFiles = Get-ChildItem -Path "$PSScriptRoot\MobileThreatDefenseConnectors" -Filter *.json
        foreach($MobileThreatDefenseConnectorsFile in $MobileThreatDefenseConnectorsFiles) {
            $MobileThreatDefenseConnector = Get-Content -Path $MobileThreatDefenseConnectorsFile.FullName | ConvertFrom-Json -AsHashtable -Depth 100
            if($MobileThreatDefenseConnectors.id -contains $MobileThreatDefenseConnector.id) {
                Invoke-GraphRequest -Method PATCH -Uri "https://graph.microsoft.com/beta/deviceManagement/mobileThreatDefenseConnectors/$($MobileThreatDefenseConnector.id)" -Body $MobileThreatDefenseConnector | Out-Null
                Write-Host "Updated mobile threat defense connector '$($MobileThreatDefenseConnector.id)'." -ForegroundColor Green
            }
        }
    }
    catch {
        throw "Failed to add mobile threat defense connectors: $_"
    }
}