Share via

status emel

Muhammad Adib Bin Rahim 0 Reputation points
2025-10-07T09:04:12.66+00:00

"How can I check or generate a list of email users who have not logged in for more than 3 months in Microsoft 365?"

Exchange Online
Exchange Online

A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Kha-N 8,260 Reputation points Microsoft External Staff Moderator
    2025-10-07T11:25:58.8633333+00:00

    Hi @Muhammad Adib Bin Rahim,

    Welcome to the Microsoft Q&A forum, and thank you very much for reaching out.

    If I understand correctly, you're looking to generate a list of users who have not logged in to Microsoft 365 for more than 3 months.

    Please note that as a Microsoft Q&A moderator, I do not have access to your specific environment or configuration. However, I’ll do my best to assist you using official documentation and by testing in a controlled environment.

    Based on my research and testing environment, you can generate and export inactive user list via Microsoft Graph PowerShell.

    However, before following these steps, kindly make sure you have the one of the roles and licenses below, as they are required to access sign-in activity data through Microsoft Graph:

    • Roles: Reports Reader, Global Administrator, Security Reader
    • License: Microsoft Entra ID P1 or P2

    First, you would need to install the Microsoft Graph module for PowerShell. This module allows you to interact with Microsoft 365 services programmatically.

    You can install it by running this command in PowerShell:

    Install-Module Microsoft.Graph -Scope CurrentUser
    

    For more information, I highly recommended you check on this Microsoft Article here.

    Once the module is installed, you’ll need to sign in to Microsoft Graph with the right permissions. Specifically, you’ll need:

    • AuditLog.Read.All : to read sign-in logs
    • User.Read.All : to read user profile data

    Here’s the command to connect:

    Connect-MgGraph -Scopes "AuditLog.Read.All", "User.Read.All"
    

    Once you able to sign in, you will need to define a threshold date as this helps determine which users are considered inactive. Since you're looking for users who haven't signed in for more than 90 days, we can use PowerShell’s built-in Get-Date function along with AddDays to calculate that date dynamically. This way, the script always compares against the current date without needing manual updates.

    For example:

    $ThresholdDate = (Get-Date).AddDays(-90).ToString("yyyy-MM-dd")
    

    This command sets the threshold to 90 days ago from today, and formats it in a way that’s compatible with filtering sign-in timestamps. You can easily adjust the number (e.g., -20 for 20 days) depending on your needs.

    Once $ThresholdDate is set, you can run a query to list users whose last sign-in was before that date. You can use the Get-MgUser command below to retrieve their sign-in activity details.

    Get-MgUser -Property id, displayName, signInActivity | Where-Object {     $_.signInActivity.lastSignInDateTime -lt $ThresholdDate } | Select-Object displayName,     @{Name="LastSignInDateTime";Expression={$_.signInActivity.lastSignInDateTime}},     @{Name="LastNonInteractiveSignInDateTime";Expression={$_.signInActivity.lastNonInteractiveSignInDateTime}},     @{Name="LastSuccessfulSignInDateTime";Expression={$_.signInActivity.lastSuccessfulSignInDateTime}}
    

    It will display user list as below:

    User's image

    To export the list to a file such as Excel file, you can add this line to the end of the command:

    Export-Csv -Path "C:\Your\Folder\InactiveUsers.csv" -NoTypeInformation
    

    Or combine everything into one command:

    Get-MgUser -Property id, displayName, signInActivity | Where-Object {     $_.signInActivity.lastSignInDateTime -lt $ThresholdDate } | Select-Object displayName,     @{Name="LastSignInDateTime";Expression={$_.signInActivity.lastSignInDateTime}},     @{Name="LastNonInteractiveSignInDateTime";Expression={$_.signInActivity.lastNonInteractiveSignInDateTime}},     @{Name="LastSuccessfulSignInDateTime";Expression={$_.signInActivity.lastSuccessfulSignInDateTime}} |
    Export-Csv -Path "C:\Your\Folder\InactiveUsers.csv" -NoTypeInformation
    

    Once the file is export, your Excel file should look like this based on my testing:
    User's image

    Additionally, I came across a helpful third-party article that walks through how to generate and export a list of inactive users in Microsoft 365. Feel free to give it a read, it might offer some useful insights or alternative approaches that could work well for your organization.

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.

    If you have any additional questions or need further clarification, please don’t hesitate to reach out. I’d be happy to assist you further.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.