Last active
August 15, 2024 04:46
-
-
Save laymanstake/0a5cc9e36e8d4ca18b0b206a04abdfcd to your computer and use it in GitHub Desktop.
User login report from Entra ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module Microsoft.Graph.Users | |
$Scopes = @( | |
"User.Read.All", | |
"Directory.Read.All" , | |
"AuditLog.Read.All" | |
) | |
Connect-MgGraph -Scopes $Scopes | |
$Users = get-mguser -all -Property UserPrincipalname | |
$report = $Users | % { Get-MgUser -userid (get-mguser -UserId $_).id -Property DisplayName,Id,JobTitle,Mail,UserPrincipalName, SignInActivity, AccountEnabled | % { | |
New-Object PSObject -Property @{ | |
DisplayName = $_.DisplayName | |
Id = $_.Id | |
Mail = $_.Mail | |
UserPrincipalName = $_.UserPrincipalName | |
LastSignInDateTime = $_.SignInActivity.LastSignInDateTime | |
LastNonInteractiveSignInDateTime = $_.SignInActivity.LastNonInteractiveSignInDateTime | |
Enabled = $_.AccountEnabled | |
} }} | Select DisplayName,Id,Mail,UserPrincipalName,LastSignInDateTime,LastNonInteractiveSignInDateTime,Enabled | |
$report | Export-Csv -nti "C:\temp\UserloginReport.csv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment