Azure AD Sign-in logs

Roger Roger 6,471 Reputation points
2022-09-02T03:44:31.653+00:00

Hi All

i have 10 users in csv file. i want to import the csv file and get their last Sign-in logs from Azure AD. i can see from GUI but there are lot of logs. i would like get it from powershell by connecting to azure AD. please guide me.

users
user1@mydomain.com
user2@mydomain.com

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,535 questions
{count} votes

Accepted answer
  1. Harpreet Singh Matharoo 8,221 Reputation points Microsoft Employee
    2022-09-03T07:03:41.303+00:00

    Hello @Roger Roger

    Thank you for being patient while I was working on a script to fetch user details from CSV and print the Last Sign-In details for them. I would like to confirm that as of today this is only possible using Microsoft Graph PowerShell Module.

    • You need to install Microsoft Graph PowerShell Module using command "Install-Module Microsoft.Graph -Scope CurrentUser". For more information you can refer following documentation: Install the Microsoft Graph PowerShell SDK
    • You would need to generate CSV with list of users in following format:

    237370-image.png

    • Once Graph Module is installed and CSV is generated you should be able to execute following script.
       Connect-MgGraph -Scopes 'User.Read.All'  
       $csv = Import-Csv -Path "Enter Input CSV file"  
       foreach ($Id in $csv)  
       {  
       $user = Get-MgUser -UserId $Id.ObjectId -Property 'SignInActivity'  
       If ($User.SignInActivity.LastSignInDateTime -eq $null)  
       {  
       Write-host "User "$Id.UserPrincipalName" has never signed in" -ForegroundColor Red   
       }  
       else  
       {  
       Write-Host "Last SignIn Date for user "$Id.UserPrincipalName" is "$user.SignInActivity.LastSignInDateTime""  
       }  
       }  
      
    • Output of the Script would be similar to screenshot below:

    237436-image.png

    I hope this helps you achieve the results you are looking for.

    ----------

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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