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
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments