Created
April 22, 2025 18:31
-
-
Save andyrobbins/c0e8b54bfb6a6a26f4db589a52e244b5 to your computer and use it in GitHub Desktop.
Get Entra Signins
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
$URI = 'https://graph.microsoft.com/beta/auditLogs/signIns?api-version=beta&source=kds' | |
$Count = 0 | |
do { | |
#$AppToken = (Get-MSGraphTokenWithClientCredentials ` | |
# -ClientID "..." ` | |
# -ClientSecret "..." ` | |
# -TenantName "...").access_token | |
$AppToken = $GlobalAdminToken.access_token | |
Write-Host "Enumerating page" $Count | |
$Results = Invoke-RestMethod ` | |
-Headers @{ | |
Authorization = "Bearer $($AppToken)" | |
} ` | |
-URI $URI ` | |
-UseBasicParsing ` | |
-Method "GET" ` | |
-ContentType "application/json" | |
if ($Results.value) { | |
$Results.value | %{ | |
$Object = $null | |
$SignIn = $_ | |
$UserID = $SignIn.userId.toString().toUpper() | |
$DeviceId = ($SignIn | Select -Expand deviceDetail).deviceId.toString().toLower() | |
If ($UserID -And $DeviceId) { | |
$Object = New-Object PSCustomObject | |
$Object | Add-Member Noteproperty 'UserID' $UserID | |
$Object | Add-Member Noteproperty 'DeviceID' $DeviceID | |
$Object | Export-CSV -Append -NoTypeInformation signins.csv | |
} | |
} | |
} else { | |
$Results | %{ | |
$Object = $null | |
$SignIn = $_ | |
$UserID = $SignIn.userId.toString().toUpper() | |
$DeviceId = ($SignIn | Select -Expand deviceDetail).deviceId.toString().toLower() | |
If ($UserID -And $DeviceId) { | |
$Object = New-Object PSCustomObject | |
$Object | Add-Member Noteproperty 'UserID' $UserID | |
$Object | Add-Member Noteproperty 'DeviceID' $DeviceID | |
$Object | Export-CSV -Append -NoTypeInformation signins.csv | |
} | |
} | |
} | |
$uri = $Results.'@odata.nextlink' | |
$Count += 1 | |
} until (!($uri)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment