Thank you for posting this in Microsoft Q&A.
I understand you're attempting to retrieve the LastSignInDateTime for guest users using a PowerShell script, but it returns a null value even though the sign-in logs indicate the user has logged in recently.
You can use the following PowerShell script:
$guests = Get-AzureADUser -Filter "userType eq 'Guest'" -All $true
foreach ($guest in $guests) {
$Userlogs = Get-AzureADAuditSignInLogs -Filter "userprincipalname eq `'$($guest.mail)'" -ALL:$true
if ($Userlogs -is [array]) {
$timestamp = $Userlogs[0].createddatetime
}
else {
$timestamp = $Userlogs.createddatetime
}
$Info = [PSCustomObject]@{
Name = $guest.DisplayName
UserType = $guest.UserType
LastSignin = $timestamp
}
$Info | Export-csv C:\GuestUserLastSignins.csv -NoTypeInformation -Append
Remove-Variable Info
}
Write-Host -ForegroundColor Green "Exported Logs successfully"
Hope this helps. Do let us know if you any further queries.
Thanks,
Navya.
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful. And, if you have any further query do let us know.