Lastlogon export csv

Iron Contributor


Need help understanding the best way to export a list that shows me the lastlogon for users, and then export to .csv . Can i use the below command to achieve this ?




3 Replies
Best use the signInActivity property, here's a sample script I wrote a while back:
Thanks for the reply. Can you elaborate on why its best to use graph? I am noticing that the command "Get-AzureADAuditSignInLogs" is not showing me date\time that i would expect. Example if i use graph, i can see date\time for particular user. If run the command below it returns 0 results
Get-AzureAdAuditSigninLogs -top 1 -filter "userPrincipalName eq ''"

I am using the below code in graph. Appears to be working
Connect-MgGraph -ClientId $appid -TenantId $TenantId -Certificate $cert | out-null

function queryAADUserLastSignin{
$uri = "`$select=Displayname,signInActivity,userPrincipalName,userType,externalUserState,externalUserStateChangeDateTime,creationType,createdDateTime,onPremisesSyncEnabled,accountEnabled,mail"
$results = Invoke-MgGraphRequest -Uri $uri -Method GET -OutputType PSObject
$results.value | select displayname, userPrincipalName,userType,externalUserState,externalUserStateChangeDateTime,creationType,createdDateTime,accountEnabled, `
$uri = $Results.'@odata.nextlink'
}until ($uri -eq $null)

queryAADUserLastSignin | export-csv .\user_export1.csv -NoTypeInformation
Because the Azure AD module is not receiving any updates and will be deprecated in favor of Graph.