Fetch Sign-In Logs of Legacy Authentication Applications Using Microsoft Graph PowerShell

IMPORTANT:
Modern Cloud Update (2026):
Basic Authentication for Exchange Online protocols (IMAP4, POP3, EAS, Remote PowerShell) is retired globally by Microsoft. Organizations must continuously monitor their sign-in logs to identify rogue connection attempts, outdated legacy clients, or compromised credentials testing legacy endpoints.
> This article has been updated to use the modern Microsoft Graph PowerShell SDK (Get-MgAuditLogSignIn) to query and export legacy authentication attempts at scale.

While Microsoft Entra ID Conditional Access policies can block legacy authentication, administrators frequently need to query and export historical sign-in telemetry beyond the 250,000 log export limit enforced in the Entra ID Admin Center GUI.

Using the Microsoft Graph PowerShell SDK allows you to page through millions of sign-in events programmatically, filter by clientAppUsed, and pinpoint every IP address and user account still attempting basic authentication.


Modern Method: Microsoft Graph PowerShell SDK

Prerequisites & Permissions

To query Entra ID sign-in logs, the calling account or App Registration must have the AuditLog.Read.All permission scope:

POWERSHELL
# Install the Reports module from PSGallery
Install-Module Microsoft.Graph.Reports -Scope CurrentUser -Repository PSGallery -Force

# Connect to Microsoft Graph
Connect-MgGraph -Scopes "AuditLog.Read.All", "Directory.Read.All"

Step 1: Identifying Legacy Protocol Sign-Ins

In Microsoft Graph, legacy authentication protocols are represented under the clientAppUsed attribute of the signIn resource. Common legacy client identifiers include:

  • Authenticated SMTP
  • AutoDiscover
  • Exchange ActiveSync
  • Exchange Online PowerShell
  • IMAP4
  • POP3
  • MAPI Over HTTP (older unauthenticated clients)
  • Other clients

Step 2: Querying Legacy Sign-In Events via PowerShell

The following command queries recent non-interactive and interactive sign-in events where legacy protocols were invoked:

POWERSHELL
# Filter for legacy authentication attempts in the last 7 days
$legacyFilter = "createdDateTime ge 2026-10-28T00:00:00Z and clientAppUsed ne 'Browser' and clientAppUsed ne 'Mobile Apps and Desktop clients'"

$legacySignIns = Get-MgAuditLogSignIn -Filter $legacyFilter -Top 100 -Property "CreatedDateTime", "UserPrincipalName", "AppDisplayName", "ClientAppUsed", "IpAddress", "Status"

$legacySignIns | Select-Object CreatedDateTime, UserPrincipalName, ClientAppUsed, IpAddress, @{n="Status";e={$_.Status.ErrorCode}} | Format-Table -AutoSize

Production Audit Script: Export Legacy Auth Report to CSV

Here is a complete, production-ready script that queries sign-ins, parses legacy protocols, resolves location data, and outputs an executive CSV report.

POWERSHELL
<#
.SYNOPSIS
    Exports Microsoft Entra ID sign-in logs for legacy authentication protocols to CSV.
.DESCRIPTION
    Scans Entra ID sign-ins via Microsoft Graph, filtering for legacy protocols
    (POP3, IMAP4, SMTP AUTH, EAS, etc.) and generating an actionable CSV audit.
.NOTES
    Author: Sunil Chauhan (https://www.lab365.in)
#>

[CmdletBinding()]
param (
    [Parameter(Mandatory = $false)]
    [int]$DaysBack = 7,

    [Parameter(Mandatory = $false)]
    [string]$ExportPath = ".\LegacyAuth_SignIn_Report_$(Get-Date -Format 'yyyyMMdd_HHmmss').csv"
)

# Connect to Graph if not connected
if (-not (Get-MgContext)) {
    Connect-MgGraph -Scopes "AuditLog.Read.All", "Directory.Read.All"
}

$startDate = (Get-Date).AddDays($DaysBack).ToString("yyyy-MM-ddTHH:mm:ssZ")
Write-Host "[*] Auditing legacy sign-in logs since: $startDate" -ForegroundColor Cyan

# Known legacy clientAppUsed signatures
$legacyProtocols = @(
    "Authenticated SMTP", "AutoDiscover", "Exchange ActiveSync",
    "Exchange Online PowerShell", "IMAP4", "POP3", "Other clients"
)

# Graph OData filter
$filter = "createdDateTime ge $startDate"

Write-Host "[*] Fetching sign-in logs from Microsoft Graph..." -ForegroundColor Yellow
$signIns = Get-MgAuditLogSignIn -Filter $filter -All -Property "CreatedDateTime", "UserPrincipalName", "ClientAppUsed", "IpAddress", "Location", "Status", "AppDisplayName"

Write-Host "[+] Total sign-in records fetched: $($signIns.Count)" -ForegroundColor Green

$legacyEvents = [System.Collections.Generic.List[PSCustomObject]]::new()

foreach ($log in $signIns) {
    if ($log.ClientAppUsed -in $legacyProtocols) {
        $legacyEvents.Add([PSCustomObject]@{
            Timestamp        = $log.CreatedDateTime
            UserPrincipalName= $log.UserPrincipalName
            ClientAppUsed    = $log.ClientAppUsed
            Application      = $log.AppDisplayName
            IPAddress        = $log.IpAddress
            City             = $log.Location.City
            Country          = $log.Location.CountryOrRegion
            ResultStatus     = if ($log.Status.ErrorCode -eq 0) { "Success" } else { "Failure ($($log.Status.FailureReason))" }
            ErrorCode        = $log.Status.ErrorCode
        })
    }
}

if ($legacyEvents.Count -gt 0) {
    Write-Host "[!] Found $($legacyEvents.Count) legacy authentication attempt(s)!" -ForegroundColor Red
    $legacyEvents | Export-Csv -Path $ExportPath -NoTypeInformation -Encoding utf8
    Write-Host "[+] Report exported to: $ExportPath" -ForegroundColor Green
} else {
    Write-Host "[✓] Zero legacy authentication sign-ins found in the last $DaysBack day(s)." -ForegroundColor Green
}

Blocking Legacy Authentication via Conditional Access

Once you have verified that valid business workloads and service accounts have transitioned to modern authentication (OAuth 2.0 / App Registrations), enforce a tenant-wide block:

  1. Navigate to Microsoft Entra admin center > Protection > Conditional Access.
  2. Create a new policy: "Block Legacy Authentication".
  3. Users: Include All users (ensure you exclude break-glass emergency accounts).
  4. Target resources: Select All cloud apps.
  5. Conditions > Client apps: Check Exchange ActiveSync clients and Other clients.
  6. Access controls > Grant: Select Block access.
  7. Enable the policy in Report-only mode for 72 hours, review logs, and then switch to On.

Archival Reference & Historical Script

For historical interest, the original custom PowerShell script created during the initial basic authentication deprecation announcement is preserved in the author's GitHub repository:


Related reading: Migrating from Windows PowerShell 5.1 to PowerShell 7 for Microsoft Graph.