Export Entra ID Sign-In Logs for Specific Apps with PowerShell & Microsoft Graph

Introduction

Microsoft Entra ID (formerly Azure AD) sign-in logs are a goldmine for troubleshooting, auditing, and security investigations. Sometimes, you don’t want all the data – you want to focus on a subset of sign-ins that match specific criteria.

In my case, I needed:

  • Sign-ins from specific apps (by App ID or name)
  • Unmanaged devices (IsManaged = false)
  • Devices running Windows 10
  • Data from the last 30 days

And of course, I wanted it exported to CSV for further analysis in Excel or Power BI.

Here’s the solution I built – you can grab the full script from GitHub – and below, I break down the most important parts so you can adapt it to your environment.

Prerequisites

Before running the script, you’ll need:

  • Microsoft Graph PowerShell SDK v2
  • AuditLog.Read.All permissions in Microsoft Graph
  • PowerShell 5.1 or newer (script works on Windows PowerShell & PowerShell 7+)

Use Cases

  • Conditional Access validation – Verify unmanaged devices are blocked or flagged
  • Shadow IT detection – Identify personal devices accessing corporate apps
  • Incident response – Focus investigations on risky app/device combos
  • Geographic anomaly detection – Spot unusual login locations
  • Compliance auditing – Provide auditors with exact unmanaged access attempts
  • User awareness – Identify and train users with risky sign-in patterns

How It Works

Parameters (IDs are fastest)

  • AppIds → fastest filter, avoids display name typos
  • AppNames → slower, but works if IDs are unknown
  • DaysBack → last N days to query
  • OutCsv → output file path

Connect to Graph

  • Uses AuditLog.Read.All – admin consent required
  • Reconnects only if you’re not already signed in

Time window

  • Always uses UTC
  • "o" format = ISO 8601

App filter (OR groups)

  • Supports both IDs and display names
  • Escapes single quotes in names to avoid OData errors

Device & OS filter

  • Exact match to Windows10
  • Can extend to startswith() for variants

Final OData filter

  • Combines all conditions into one Graph query

Explicit $select

  • Ensures Graph returns required fields
  • Requests nested objects

REST call + paging

  • Avoids submodule loading quirks
  • Handles >999 rows with paging

Flatten nested objects

  • Converts nested objects to flat CSV columns

Export

  • UTF-8 output for compatibility

Summary

Filtering sign-in logs directly in Microsoft Graph makes investigations faster and reporting cleaner. This approach:

  • Targets unmanaged Windows 10 devices
  • Filters by specific applications
  • Flattens nested JSON into CSV
  • Handles paging automatically

Whether for incident response, compliance, or policy validation, this is a repeatable and efficient method to get exactly the sign-in data you need.

Script Source

The complete script is available on the Azure365Addict GitHub.
Feel free to download, customize it to your specific needs, and improve your mailbox management processes.

If you have any questions or want to extend this into automated cleanup or reporting, feel free to reach out.

Happy scripting!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top