Created
May 31, 2016 18:16
-
-
Save rayterrill/ca9ef8967c86f4f13e49bd4894629da7 to your computer and use it in GitHub Desktop.
This file contains 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 AWSPowerShell | |
#get a date 90 days ago to use to calculate old credentials | |
$date90DaysAgo = (Get-Date).AddDays(-90) | |
#gather all of our iam users | |
$users = Get-IAMUsers | |
#iterate each of my uesrs | |
foreach ($u in $users) { | |
#grab all the keys for a user | |
$keys = Get-IAMAccessKey -Username $u.Username | |
#iterate each of the user's keys | |
foreach ($k in $keys) { | |
if ($k.CreateDate -lt $date90DaysAgo) { | |
Write-Host "Key [$($k.AccessKeyId)] from [$($k.UserName)] is older than 90 days and needs to be rotated." -ForegroundColor Yellow | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment