IAMinerva
HomeBlogAbout
m3M365 NewscoMicrosoft CopilotteMicrosoft TeamsshSharePoint & OneDriveinIntune & SecurityexExchange & OutlookpoPower PlatformazAzure & Entra IDtuTutorials & GuidesevEvents & ConferencesseSecuritywiWindows
IAMinerva

Professional blog dedicated to the Microsoft 365 ecosystem.

Quick links

HomeBlogAboutNewsletter

Stay informed

Get the latest Microsoft 365 news delivered straight to your inbox.

© 2026 IAMinerva. All rights reserved.

Built withNext.js&Tailwind
Détection proactive des menaces M365 : surveillance en temps réel des connexions depuis des emplacements inhabituels
BlogSecurityProactive M365 Threat Detection: Real-Time Monitoring of Sign-In Attempts from Unusual Locations
Security#Microsoft 365#Security#KQL

Proactive M365 Threat Detection: Real-Time Monitoring of Sign-In Attempts from Unusual Locations

Comprehensive guide to configure proactive monitoring of suspicious sign-in attempts in Microsoft 365 with KQL and Log Analytics. Real-time threat detection.

Houssem MAKHLOUF
February 12, 2026
7 min read

TL;DR par Minerva

généré par IA

Comprehensive guide to configure proactive monitoring of suspicious sign-in attempts in Microsoft 365 with KQL and Log Analytics. Real-time threat detection.

Introduction

In modern cloud environments, protecting user identities is an absolute priority. Conditional Access policies represent the gold standard for strengthening access controls. However, many organizations face a recurring challenge: their employees travel frequently.

In such contexts, applying a strict conditional access policy limiting sign-ins to a fixed set of countries can prove impractical. Nevertheless, this does not mean you must remain blind to suspicious activities. This is where proactive monitoring with KQL (Kusto Query Language) comes in.

i

Why this approach?

When conditional access policies cannot block certain countries, administrators still need visibility into sign-in attempts from unexpected geographies, brute force attacks, and successful sign-ins from concerning locations.

Use Cases and Objectives

When conditional access cannot be applied to completely block certain countries, administrators need visibility into:

  • Sign-in attempts from unexpected geographies
  • Accounts targeted by brute force or password spray attacks
  • Successful sign-ins from locations that should raise concerns

By continuously monitoring sign-in attempts outside your "trusted" geography, you can stay ahead and detect potential compromises early.

Technical Prerequisites

Before executing this solution, ensure you have the following:

Required Licenses

  • Entra ID P1 or P2: Necessary to enable sign-in logs and advanced identity protection features

Azure Infrastructure

  • Log Analytics Workspace: Centralizes ingestion and querying of sign-in logs
  • Entra ID logs connected to Log Analytics

Access Permissions

Your administrator account must have at least the following roles:

  • Security Reader or Security Administrator in Azure AD
  • Log Analytics Contributor to execute and manage queries

Configuring the Log Analytics Workspace

1

Create the workspace

In the Azure portal, search for "Log Analytics Workspaces" and select Create.

Image 1

Image 2

2

Configure settings

Fill in the following information:

  • Subscription: Select your Azure subscription
  • Resource Group: Choose or create a resource group
  • Name: Enter a descriptive name (e.g., "SecurityLogs")
  • Region: Select the region closest to your organization

Image 3

Image 4

3

Validate and create

Review the configuration and click Create to deploy the workspace.

Connecting Entra ID Logs

1

Access diagnostic settings

Go to the Entra ID admin center at https://entra.microsoft.com/, then navigate to Monitoring > Diagnostic Settings.

Image 5

2

Add a diagnostic setting

Click Add diagnostic setting and configure:

  • Select SignInLogs and optionally AuditLogs
  • Check Send to Log Analytics workspace
  • Choose the workspace created previously

Image 6

3

Save the configuration

Save the configuration. SigninLogs will appear in your workspace within a few minutes to an hour, depending on activity.

✦

Ingestion delay

Once configured, you will begin to see SigninLogs in your workspace within a few minutes to an hour, depending on sign-in activity.

Executing the KQL Query

1

Access the workspace

In your Log Analytics workspace, select Logs from the left menu and close the Query hub by clicking the 'X'.

Image 7

2

Configure KQL mode

Select KQL mode in your Log Analytics workspace.

Image 8

3

Execute the query

Copy and paste the following KQL query to filter sign-in attempts from locations outside Canada (CA) and the United States (US):

🔍KQL
1// Get a list of all sign-ins (successful, failed, revoked, etc.) outside of Canada (CA) and the United States (US)
2SigninLogs
3| where Location !in ("CA", "US") and isnotempty(Location) // Location different from CANADA, US
4| extend LocalTime = datetime_add('hour', -5, TimeGenerated) // UTC-5 (CANADA Time)
5| project LocalTime, UserPrincipalName, UserDisplayName, Identity, ResourceDisplayName, Location, IPAddress, RiskState, ConditionalAccessStatus, ResultType, ResultSignature, ResultDescription, MfaDetail, RiskDetail
6| order by LocalTime desc

Click Run to execute the query.

!

Customizing locations

You can modify the locations by changing "CA" and "US" in the third line of code and adding your specific locations.

The results will include details such as: LocalTime, UserPrincipalName, Location, IPAddress, RiskState, ResultDescription.

Image 9

Saving the KQL Query

1

Save the query

Click the save button and fill in:

  • Query name: "Sign-in attempts from unusual locations"
  • Description: "Detection of sign-in attempts from suspicious geographic locations"
  • Resource type: "Log Analytics Workspaces"
  • Category: "Audit"

Image 10

Image 11

✦

Memorization

Keep the query name in a notepad, as we will use it later for alert configuration.

Configuring Automated Alerts

1

Create an alert rule

In the Log Analytics workspace, click "..." (three dots) in the top right, then select New alert rule.

Image 12

2

Configure the condition

In the Condition section:

  • Signal name: "Custom log search"
  • Query type: Aggregated logs
  • Paste your KQL query into the text area

In the Measurement section:

  • Measurement: "Table rows"
  • Aggregation type: "Count"
  • Aggregation granularity: "30 minutes"

Image 13

3

Define alert logic

Configure the following settings:

  • Operator: "Greater than"
  • Threshold value: 0
  • Time aggregation: 30 minutes
  • Override query time range: 30 min

Image 14

4

Configure actions

In the Action section:

  • Select Quick Actions (Preview)
  • Action group name: "Suspicious Sign-In Email Notification"
  • Display name: "Conn-Suspicious"
  • Notification emails: Add the email addresses that should receive the alert

Customize the alert email subject, for example: "Alert - Sign-in from an unusual location".

Image 15

5

Finalize the configuration

Configure the final details:

  • Azure Subscription: Select the appropriate subscription
  • Resource Group: Choose the resource group
  • Severity Level: 2 – Warning
  • Descriptive name: "Sign-in attempts from unusual locations"
  • Region: Choose the same region as your other resources

Image 16

Click Create to finalize and deploy the alert rule.

Image 17

Testing and Validating the System

To validate that your detection system is working properly, you can simulate a sign-in from an unusual location. In the example below, a sign-in attempt with an incorrect password from a VPN located in the United Kingdom immediately generates a notification.

Image 18

Email Notification

Here is an example of an email notification sent to the help desk:

Image 19

Verifying Results

To verify the query results directly:

  1. Return to the Log Analytics workspace
  2. Select "Logs" from the left menu
  3. Type the name of your saved KQL query in the search bar
  4. Click "Run"

Image 20

Detailed results display in the table:

Image 21

Advanced Optimizations

Adding to Favorites

For quick access to your query:

  1. Type the name of your query in the search bar
  2. Click the star icon to add it to favorites

Image 22

Image 23

Excluding Trusted IP Addresses

If you want to exclude certain trusted locations or IP addresses (offices, approved IP addresses), use this modified KQL query:

🔍KQL
1// Office IP addresses to exclude from triggering
2let AllowedIPs = dynamic([ "1.1.1.1", "8.8.8.8" ]);
3// Get a list of all sign-ins outside the country list + IP list
4SigninLogs
5| where Location !in ("CA", "US") and isnotempty(Location) // Location different from CANADA, US
6| where IPAddress !in~ (AllowedIPs) // exclude office IP addresses
7| extend LocalTime = datetime_add('hour', -5, TimeGenerated) // UTC-5 (CANADA Time)
8| project LocalTime, UserPrincipalName, UserDisplayName, Identity, ResourceDisplayName, Location, IPAddress, RiskState, ConditionalAccessStatus, ResultType, ResultSignature, ResultDescription, MfaDetail, RiskDetail
9| order by LocalTime desc
!

IP customization

Do not forget to replace the example IP addresses ("1.1.1.1", "8.8.8.8") with the actual IP addresses of your offices or trusted addresses.

Conclusion

This proactive monitoring solution enables you to maintain visibility over suspicious sign-in activities while preserving the flexibility needed for traveling employees. By combining KQL, Log Analytics, and Azure alerts, you have a robust detection system that effectively complements your existing conditional access policies.

Implementing this continuous monitoring constitutes an essential additional security layer in your Microsoft 365 identity protection strategy.

Share:
HM

Houssem MAKHLOUF

Microsoft 365 enthusiast & IT professional.

Previous article

New Intune Feature: Control Automatic MDM Enrollment When Adding Work Accounts

Feb 9, 2026
Next article

Intune Device Actions: Microsoft Restores Instant Execution of Remote Actions

Feb 15, 2026

Related articles

Classeur ancien ouvert, entouré de symboles de gestion des données et d'archivage.securite

Microsoft Purview: Optimize Data Lifecycle Management

Maximize data security with Microsoft Purview through intelligent lifecycle management and advanced features.

Jun 29, 20264 min
Cadenas stylisé avec des éléments graphiques abstraits et du texte sur la sécurité.securite

New Microsoft 365 Security Adoption Model

Discover the Microsoft 365 security adoption guide based on Zero Trust principles: modular approaches and modern strategies.

Jun 29, 20264 min
Main d'homme interagissant avec une interface numérique lumineuse et dynamique.copilot

Agents: Transforming Work with AI in Microsoft 365

Intelligent agents are redefining work in Microsoft 365 by automating complex and extended tasks. Discover their impact and adoption.

Jun 28, 20263 min