Skip to content

Script to Disable SMS Sign-In for Federated Users in Microsoft Graph

This script connects to Microsoft Graph for a specified tenant and retrieves all users with a UserType of ‘Member.’ It filters users who use federated identities for sign-in and disables their SMS sign-in authentication method by targeting the corresponding phone authentication method ID. The script provides progress updates, showing the percentage of users processed, the remaining users, and the time taken for each operation.


Ideal for: Azure AD administrators managing authentication methods for federated users

FeatureCapabilityBusiness Value
Federated User FilteringIdentifies users with federated sign-inTargeted authentication management
SMS Sign-In DisableRemoves SMS authentication methodEnhances security posture
Progress TrackingReal-time processing updatesOperational visibility
Batch ProcessingEfficient handling of multiple usersScalable operations

Terminal window
Connect-MgGraph -TenantId "xxx.onmicrosfot.com" -Scopes "User.Read.All", "UserAuthenticationMethod.ReadWrite.All"
$allusers = Get-MgUser -Property id,Userprincipalname,identities,UserType -all -Filter {UserType eq 'Member'}
$SMSenabled = $allusers | ? {$_.identities.SignInType -contains 'federated'}
$phoneAuthenticationMethodId = "3179e48a-750b-4051-897c-87b9720928f7"
$i = 0
$SMSenabled | ForEach-Object {
    $runtime =  Measure-Command {
        Disable-MgUserAuthenticationPhoneMethodSmsSignIn -UserId $_.Id -PhoneAuthenticationMethodId $phoneAuthenticationMethodId
    } | Select-Object -ExpandProperty TotalSeconds
    $i++
    $Completed = ($i/$SMSenabled.count) * 100
    $remain = $SMSenabled.count - $i
    Write-Progress -Activity "Removing Phone SignIn" -Status "Progress:$remain users remain, Last Run Time: $runtime" -PercentComplete $Completed
}

ComponentRequirementPurpose
Microsoft Graph ModuleMicrosoft.Graph PowerShell moduleAPI connectivity
Authentication PermissionsUser.Read.All, UserAuthenticationMethod.ReadWrite.AllUser and authentication method access
Admin RightsAuthentication Administrator or Global AdministratorSufficient permissions to disable methods
ParameterExampleDescription
TenantId"contoso.onmicrosoft.com"Target tenant for processing
Phone Authentication Method ID"3179e48a-750b-4051-897c-87b9720928f7"Fixed ID for SMS authentication

  1. Connect to Microsoft Graph

    • Establish authenticated connection to specified tenant
    • Verify required permissions
  2. Retrieve User Data

    • Get all member users with identity properties
    • Filter for federated authentication users
  3. SMS Sign-In Disable Process

    • Iterate through federated users
    • Disable SMS authentication method
    • Track processing time and progress
  4. Progress Monitoring

    • Display completion percentage
    • Show remaining user count
    • Log operation performance metrics

CriteriaDescriptionPurpose
UserType = ‘Member’Internal organization usersExclude guest accounts
SignInType = ‘federated’Uses federated identity providerTarget specific authentication flow
SMS Authentication EnabledHas active SMS sign-in methodUsers requiring action

MetricDescriptionUsage
Completion Percentage(processed / total) * 100Overall progress tracking
Remaining Userstotal - processedWork remaining estimate
Runtime per UserIndividual operation timePerformance analysis
Activity StatusDescriptive progress messageUser-friendly feedback

ImpactDescriptionMitigation
Authentication ChangeUsers lose SMS sign-in optionEnsure alternative methods available
Federated User FocusOnly affects federated authenticationMaintains local user SMS access
Batch ProcessingMultiple users updated simultaneouslyMonitor for authentication issues

Key Takeaway: This script provides targeted removal of SMS authentication for federated users, enhancing security posture while maintaining operational visibility through comprehensive progress tracking and performance monitoring.