You can use the Microsoft Graph Powershell module to download last sign in date / time for users from the Beta endpoint ( the signInActivity is currently not available in v1.0 ) and save the list to a .csv file. You must have the Microsoft Graph powershell module installed. This document will help you get started.

My powershell script:

# This script uses the Microsoft Graph Powershell Module: https://docs.microsoft.com/en-us/graph/powershell/get-started
# please ensure the module is installed.

$outFilePath = 'c:\temp\lastSignIns.csv'
$hasError = $false

Connect-MgGraph -scopes "Directory.Read.All", "AuditLog.Read.All"
Select-MgProfile -Name beta

try{
    $users = Get-MgUser -All -Property "id, userPrincipalName, displayName, signInActivity" -ErrorAction Stop -ErrorVariable GraphError | Select-Object -Property id, userPrincipalName, displayName, @{Name='lastSignInDateTime';Expression={$_.signInActivity.lastSignInDateTime};}
    Write-Host "Downloaded report to memory..."
} catch {
    Write-Host "Error downloading report: $GraphError.Message"
    $hasError = $true
}

if(!$hasError){
    try{
        Write-Host "Writing to .csv file..."
        $users | Export-Csv -Path $outFilePath
        Write-Host "Report saved at $outFilePath"
    } catch {
        Write-Host "Error saving .csv: $_.ErrorDetails.Message"
    }
}

Disconnect-MgGraph

3 Thoughts to “Download the user signInActivity from the beta endpoint using Microsoft Graph Powershell module.”

  1. Kees Sprangers

    Thanks, useful.

  2. Larry

    This script has been extremely useful sign I found it last year. However recently I noticed that it is not grabbing the latest sign-ins for some of the users in my tenant (typically, it’s grabbing the sign-ins from over 60 days ago). Any thoughts as to why? Has something changed to cause this to occur?

    1. Bac Hoang [MSFT]

      This is most likely due to the backend service

Leave a Reply to Larry Cancel reply