Select-MgProfile beta
$userid = (Get-MgUser -UserId '[email protected]').id
Get-MgUser -Userid $userid -Property SignInActivity | Select-Object -ExpandProperty SignInActivity | FL
#Output
LastNonInteractiveSignInDateTime : 2/2/2023 2:06:47 AM
LastNonInteractiveSignInRequestId : d8fa780f-c164-4606-b8c1-23d4702af000
LastSignInDateTime : 2/2/2023 2:06:46 AM
LastSignInRequestId : 6830f9e6-5be4-4e7d-a381-1cfbef0fc300
AdditionalProperties : {}
$Result=@()
$usersUPN = Get-MgUser -All | Select UserPrincipalName, ID
foreach($user in $usersUPN)
{
$signindate = Get-MgUser -UserId $user.ID -Property SignInActivity | Select -ExpandProperty SignInActivity
$userprops = [ordered]@{
UserPrincipalName = $user.UserPrincipalName
LastSignInDateTime = $signindate.LastSignInDateTime
LastNonInteractiveSignInDateTime = $signindate.LastNonInteractiveSignInDateTime
}
$userObj = new-object -Type PSObject -Property $userprops
$Result += $userObj
}
$Result
#Output
UserPrincipalName LastSignInDateTime LastNonInteractiveSignInDateTime
----------------- ------------------ --------------------------------
[email protected] 1/1/2023 10:53:52 AM 1/1/2023 1:14:20 PM
[email protected] 2/2/2023 2:06:46 AM 2/2/2023 2:06:47 AM
[email protected] 2/3/2023 10:24:22 AM 2/3/2023 10:47:32 PM
[email protected]
[email protected] 1/11/2023 6:20:01 AM 1/11/2023 8:40:14 AM
[email protected] 2/1/2023 9:51:25 AM 2/3/2023 9:30:49 PM
[email protected] 2/1/2023 6:35:49 AM 2/1/2023 6:35:51 AM
[email protected] 2/2/2023 8:46:56 PM 2/2/2023 8:47:37 PM
[email protected] 12/27/2022 3:43:38 PM 12/27/2022 3:43:39 PM
5/5 - (2 votes)