Get Last Login from Azure

Since long it was complicated to get the last login timestamp of all users from azure. With the introduction of MS Graph for Powershell this has changed partly.

For this to work it is expected that the Powershell 7.1 is installed and started with pwsh.exe

Install-Module Microsoft.Graph -Scope CurrentUser
Import-Module Microsoft.Graph.Users

Connect-MgGraph -Scopes "User.Read.All","Group.ReadWrite.All"

Select-MgProfile beta

Get-MgUser -All -Select DisplayName, SignInActivity, Mail, UserPrincipalName, UserType | `
 Select DisplayName, Mail, UserPrincipalName, UserType -ExpandProperty SignInActivity | `
 Select DisplayName, Mail, UserPrincipalName, UserType, LastSignInDateTime, LastNonInteractiveSignInDateTime | `
 ConvertTo-Json > c:\temp\users.json