Skip to content

Instantly share code, notes, and snippets.

@krymtkts
Created January 31, 2023 07:11
Show Gist options
  • Save krymtkts/f8a49fd5b74eefb4c13098966e220094 to your computer and use it in GitHub Desktop.
Save krymtkts/f8a49fd5b74eefb4c13098966e220094 to your computer and use it in GitHub Desktop.
Get-IAMUsers | ForEach-Object {
do {
$j = Request-IAMServiceLastAccessedDetail -Arn $_.Arn
Start-Sleep -Seconds 1
$r = Get-IAMServiceLastAccessedDetail -JobId $j
} until (
$r.JobStatus.Value -eq 'COMPLETED'
)
$d = $r.ServicesLastAccessed | Sort-Object -Descending -Property LastAuthenticated | Select-Object -First 1
[PSCustomObject]@{
Arn = $_.Arn
LastAuthenticated = if ($d.LastAuthenticated.Ticks -gt 1) { $d.LastAuthenticated }
# LastAuthenticatedEntity = $d.LastAuthenticatedEntity
LastAuthenticatedRegion = $d.LastAuthenticatedRegion
ServiceName = $d.ServiceName
}
}
# } | Format-Table | Out-String | Set-Clipboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment